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
StackOverflow
Is it possible to add SendCustomEvent and SendCustomEventDelayed with parameters to the official SDK? I am very grateful that Genesis implemented one, but I also hope the development team could consider including those functions in official SDK for better compatibility with future SDK releases.
The reason I want these functions is that although the newly released networked version covers many use cases, it does not allow non-syncable arguments, like object references. I am trying to make an event system where event calls are broadcasted to multiple receivers that come in different classes, and I want to pass object references to them as event context.
naqtn
Genesis
If you're only looking for argument support on SendCustomEvent in U#, I made a package to add support for that:
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:
Load More
→