Instantiating a GameObject with an UdonBehaviour attached to it or a child, in OnPlayerJoined, will result in an exception (in Play mode)
Blue-kun
Tested this in a fresh project with a blank (and non-blank) UdonBehaviour attached to a GameObject (or a child of it).
public override void OnPlayerJoined(VRCPlayerApi player)
{
Instantiate(TestObject);
}
The error is:
InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator[TKey,TValue].MoveNext () (at <eef08f56e2e042f1b3027eca477293d9>:0)
VRC.Udon.UdonManager.RunEvent (System.String eventName, System.ValueTuple`2[System.String,System.Object][] eventParameters) (at ./Packages/com.vrchat.worlds/Runtime/Udon/UdonManager.cs:896)
VRC.SDK3.ClientSim.ClientSimUdonManagerEventSender.RunEvent (System.String eventName, System.ValueTuple`2[System.String,System.Object][] programVariables) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/System/ClientSimUdonManagerEventSender.cs:16)
VRC.SDK3.ClientSim.ClientSimUdonManager.OnPlayerJoined (VRC.SDK3.ClientSim.ClientSimOnPlayerJoinedEvent joinEvent) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/System/ClientSimUdonManager.cs:106)
VRC.SDK3.ClientSim.ClientSimEventDispatcher.SendEvent[T] (T clientSimEvent) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/Events/ClientSimEventDispatcher.cs:62)
VRC.SDK3.ClientSim.ClientSimPlayerManager.DispatchPlayerJoinedEvent (VRC.SDKBase.VRCPlayerApi player) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/System/ClientSimPlayerManager.cs:117)
VRC.SDK3.ClientSim.ClientSimPlayerManager.OnClientSimReady () (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/System/ClientSimPlayerManager.cs:109)
VRC.SDK3.ClientSim.ClientSimMain+<InitializeClientSim>d__40.MoveNext () (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/System/ClientSimMain.cs:354)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <b41119cc6741409ea29f63c7f98de938>:0)
Log In
SpaceCowboy121
I have a related but not exactly the same error.
If I instantiate a object in OnPlayerJoined I don't get a error. In the editor until I try to access it's Udon component.
GameObject gameObject = (GameObject)Instantiate(cowboyUserDataPrefab);
CowboyUserData otherScript = gameObject.GetComponentInChildren<CowboyUserData>();
Of important note if I do this and run it in the game using test mode it works without error. Also if I move this same code to Start() instead of OnPlayerJoined this code works fine as well.
tp․jp
In the latest SDK 3.5.2, if the above error occurs, subsequent processing may result in the absence of a valid camera due to incorrect handling, rendering it impossible to perform operations with ClientSim, making verification of functionality exceedingly difficult.