Changing color of Gameobjects with a pen-like thing but the sync isnt always working

Hello everyone.

I have an error that doesn’t always occur but sometimes and I really can’t understand why it occurs and how I can fix it.

My context: The following script is on the GameObject, the color of which should be changed with different “pens”. (If I touch the GameObject with a red pen, the GameObject should turn red. etc. I currently have 16 colors.) That means I have prefabs that have two Udon behaviors, one of which is the following script.

The problem: Sometimes it works wonderfully! Sometimes not at all, sometimes only locally. Sometimes the material is only changed when you pick up the GameObject. (It always works locally, but synchronization for the other players sometimes doesn’t work. So far I haven’t been able to find a reason for this.)

The script should also have other pens with a function other than changing the color. One of these pins is supposed to bring the GameObject back into the ObjectPool, which has always worked so far.

All public variables are filled with the important prefabs. The pens that are supposed to change the color are numbered (I tried out a different approach that converts the names of the pens to ints, which can then be used directly - as an alternative to the for-loop, as I would really like to get rid of that.)

I hope you can help me. Because I have been looking for the error and a solution for almost 5 hours…

Thank you in advance!



A couple things I notice:

  • SetOwner has no GameObject argument passed in, I recommend passing this to it.
  • You SetOwner twice, this isnt nesssisary, maybe remove the last one just in case
  • OnTriggerEnter runs for all clients, so when this happens, everyones script is trying to claim and set the color of this. If this is an issue, then testing this script alone it should work better than with people.
  • Set SelectedColor Im pretty sure (correct me if Im wrong) will only trigger a change if the value is different. Although I think in this case it doesnt matter.
  • in VRCObjectPool.Return you arent passing this to it, Im not sure if it needs a reference too.

With this in mind, I think the main issue is the OnTriggerEnter running for all clients causing ownership fighting.

I dont actually think you need to SetOwner at all. You could let the host control and manage the color for everyone, for people non-owner they might get some delay, but it might work better. Instead of setting the owner, check if the local user is the owner, and remove all SetOwner’s. If so, continue. You could try something like this:

Although if you want to keep it like you do to have snappy no laggy colorydo, you will need to make sure OnTriggerEnter only runs if the local user is holding the pen. Since VRCObjectPickups claim the object whenever you hold them, you could do this with something like this maybe

If none of that works, then Im not too sure what your issue is. Udon is so annoying sometimes! But I believe in you! :blue_heart: