[588] Heap values are not initialized in some cases so GetProgramVariable() returns null when it shouldn't and SetProgramVariable() doesn't work
complete
Merlin
If you use GetProgramVariable on an UdonBehaviour immediately after it has been initialized via VRCInstantate.Instantiate, it will return null for valid variable names since the heap has not been initialized yet. In order for the heap to be valid you need to wait for the UdonBehaviour's first update for the variables to be valid. Another case where GetProgramVariable will fail is if the UdonBehaviour is disabled and has never been enabled.
In a similar vein, if you set any heap variable via SetProgramVariable() before its heap has had a chance to initialize, SetProgramVariable will silently fail and any attempts to get the variable via GetProgramVariable() before initialization after setting it will return null.
SendCustomEvent also fails in a similar way https://vrchat.canny.io/vrchat-udon-closed-alpha-bugs/p/sendcustomevent-fails-on-gameobjects-that-where-instantiated-in-the-same-functio
It would be good if these functions (SetProgramVariable, GetProgramVariable, and SendCustomEvent, along with possibly SendCustomNetworkEvent) would force the UdonBehaviour to initialize itself if it hasn't already been initialized before they execute any logic. Right now it's unexpected behavior for people who instantiate game objects; I've seen a number of people run into issues with this already and need to work around it by delaying initializing the instantiated object by a frame which gets messy very quickly and requires them to register an Update function in cases where they may not need to otherwise or they need to move their initialization logic that depends on the initializer into the initializee which means they have a difficult time determining what behaviour instantiated them. It will probably also be confusing if people try to interact with a disabled component.
Log In
Momo the Monster
complete
T
TCL
in progress
P
PileOfMeeps
I didn't really understand from reading this at first that this meant you cant do:
GameObject hudObject = VRCInstantiate(ToDispense);
Behavior hud = hudObject.GetComponent<Behavior>();
Which makes it immensely more difficult to track and hand off player data, which is already hard enough.
Momo the Monster
tracked
Momo the Monster
Thanks for the in-depth report, Merlin. We're looking at several issues around VRCInstantiate, this will be a helpful test as we fix up that node.
Merlin
Momo the Monster: Just wanted to make sure this was clear, it's also an issue on disabled UdonBehaviours that have never been enabled, not just VRCInstantiated behaviours. This has been a point of confusion for people because GetComponent<T>() on UdonBehaviours in U# needs the heap to be initialized on UdonBehaviours to work correctly.