Array Instances Becoming Null

I am trying to create a material toggle using 3 scripts: Toggle, Parent Controller, and Child.

This is the flow chart, basically. The Parent Controller is parents of both the other Udon scripts.

I created this system with the assistance of some great folks in #udon-support on the discord.

The reason this system exists is to allow easier management of materials in the long run. LTCGI is a library to have video emission on materials. But obviously, it is quite intensive still. I have a toggle so it can be off by default so it doesn’t increase GPU load.

In order to do a toggle with a single script, I would’ve needed to at least store one array of objects and then an array of all materials. This can work, but can make it difficult in the long run to maintain materials and objects. By using this registration method, I can just add or modify objects like I would normally, rather than managing a separate script.

It is almost working. Registering the scripts with each other works just fine, and the toggle technically works. However, the LTCGI_Child instances that I am storing on the LTCGI_Parent_Controller are becoming null.

Calling Debug.Log before and after it is added to the main array registeredChildren, it shows the object exists. Calling Debug.Log on child in foreach which is iterating on registeredChildren, the child is then null.

I did try to call the LTCGI_Parent_Contoller in LTCGI_Toggle only on toggle, to try to make sure the instance I have is updated, but this doesn’t seem to work either. Just not sure what to try here. I am not sure how the instances are disappearing.

Here is the code:


In your LTCGI_Parent_controller at line 14 you do array.copy and specify to copy 0 items. So no array items are getting moved to your temp array.
Removing the 0 should fix it.