Add an optional parameter to custom event
interested
naqtn
If I want to pass a parameter to custom event receiver, even now, I could it by using public program variable and executing SetProgramVariable before SendCustomEvent. Comparing that, for example, OnCollisionEnter event uses implicitly defined variable "onCollisionEnterOther".
I think it will be useful and user friendly if parameter passing can be written directly in sender side SendCustomEvent node and receiver side CustomEvent node as a kind of syntax sugar.
Log In
Chdata
It's absolutely insane that I can't just put variables into functions...
NothingToFear
Had always been eager to see this feature. Currently even the simplest integer arg, i have to work around by adding them to name of the event listener function.
Krey()
Will note that you can kinda do this by extending OnDeserialization() where when you sync a variable you can then call a function and pass it that new synced variable. That said this only works with variables you can sync with udon and would be much cleaner if we could just pass a variable with a custom event.
Happyrobot33
Stupidly this is proven to be entirely possible since U# can do this perfectly fine
Enverex
It honestly blows my mind that Udon basically has functions but doesn't allow for arguments. How is that not one of the most basic features there on day 1?
G
Gupua20
One of the uses of SendCustomNetworkEvent is to change the variables of the other person's object. SendCustomNetworkEvent with optional parameters can simplify your code in the uses.
When you need to change a variable of an object which you do not own, you cannot simply change the variable, like "x=1;".
You can use "SendCustomNetworkEvent" but it does not support parameters. If you knew the variable x takes few possibility (like x is only 0, 1, 2, ..., 32), you can imprement functions named "SetXto0", "SetXto1", "SetXto2", ..., "SetXto32" and make the owner change the variable through "SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.Owner, 'SetXto0')". This system works but loses readability.
I found several posts on twitter using SendCustomNetworkEvent in a mentioned way:
If you can fire SendCustomNetworkEvent with optional parameters, you need to implement just one function like "SetX(int x)". This method is also compatible with other values than 0~32.
G
Gupua20
I found implementations that provide networking events with optional parameters, but I did not check yet if it works:
Snowdrama
Came here to post this exact thing. Similar to the already existing Unity SendMessage(string, object) things like SendCustomEvent and SendCustomNetworkEvent, should also include a payload object. Putting object here as I'd like it to support structs/tuples, groups of variables.
Allowing values to be attached as payloads to events would allow for events to be like(Tuple Example):
SendCustomNetworkEvent("DealDamage", (playerId, damgeAmount));
Then all event listeners need is to implement some kind of interface for accepting named parameters
Entchenklein Entchenklein
this would make things so mutch easyer but please dont make a limit how many variables you can pass through the event
Kaj
This should be a feature of network events too. Currently there's no easy way to quickly pass values to a specific player without first taking ownership of a synced variable and alerting every other player to this change - way too much network overhead.
Load More
→