RealtimeView.RequestOwnershipOfSelfAndChildren() causes error: Collection was modified
Any ideas how to fix this?
InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.Generic.List
1+Enumerator[T].MoveNextRare () (at <b4bf55bf6893420ebddeeda99394cb6d>:0)
System.Collections.Generic.List
1+Enumerator[T].MoveNext () (at <b4bf55bf6893420ebddeeda99394cb6d>:0)
Normal.Realtime.RealtimeView.RequestOwnershipOfSelfAndChildren () (at <b5c6492a452a4d33b2ddfc50f28da200>:0)22 Replies
Hi @RoyNexus. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but the knowledge sources do not contain any information about the internal implementation or known issues with
RealtimeView.RequestOwnershipOfSelfAndChildren()
causing a "Collection was modified" error. There is no documentation or troubleshooting guidance for this specific exception in the provided materials.
If you are encountering this error, it may be due to modifying a collection (such as adding or removing child views or components) while iterating over it inside the RequestOwnershipOfSelfAndChildren()
method. However, without explicit documentation or guidance from the knowledge sources, I cannot provide a definitive solution or workaround.
For further assistance, you may want to consult the official Normcore support channels or community forums, as this issue is not covered in the current documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@362795742198235136> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
for more context I have a single scene entity of the RealtimeView, even if I trigger
RequestOwnershipOfSelfAndChildren()
via script or through the editor UI I get the same errorHey, trying to repro this bug on our side
Is this on Normcore 2.15.4?
I made a quick setup where I parented multiple RealtimeViews & RealtimeTransforms in the scene and clicked "Request Ownership of Self and Children" on the root:

but I wasn't able to get the error
2.15.1
This particular RealtimeView only has a custom model attached to it. But it only has a custom component, but no children
maybe it makes no sense to call
RequestOwnershipOfSelfAndChildren()
, but surprised that error happens anyway
I take that back, I do want the ownership of HostSync as wellDowngraded to 2.15.1 but not able to trigger it. Lmk if this setup is different from yours:

Test A is:
yeah, I'm guessing I'm trying to claim ownership of the model while is still not ready?

Hmm this one works fine too:
If you can put together a minimal repro project I'd be glad to take a look
yeah, actually I think I found what triggers it!
I have this other realtime view (separate in the hierarchy) that as soon as I do _realtimeView.RequestOwnershipOfSelfAnChildren() on it, it triggers the Collection error on the HostSync.cs.
I'll clarify here:
This is the code on PlayerSpawnPoseSync

The views for HostSync and PlayerSpawnPoseSync are independent of each other on the hierarchy. And they are both in the scene

as soon as I do RequestOwnershipOfSelfAndChildren() on PLayerSpawnPoseSync's RealtimeView. For some reason HostSync is affected????
I guess a better question is. Is the RealtimeView ready for claiming ownership of it and its children as soon as I'm connected to realtime room?
or should I wait for
RealtimeView.didReplaceAllComponentModels
event to then claim ownership?We only fire
Realtime.didConnectToRoom
after we set the models on all the scene views, so they should be ready for ownership changes by thenthanks, that's very helpful.
Ok so the issue is in my code, and it works as follows:
HostSync's RealtimeView.RequestOwnershipOfSelfAndChildren() => HostSync's
OnOwnerIDSelfDidChange
=> hostSelected?.Invoke(newHostId)
=> PoseSelection listening to hostSelected
event => Call to PlayerSpawnPose's Occupy
=> call to PlayerSpawnPose's RealtimeView.RequestOwnershipOfSelfAndChildren()
All of this happens on the same frame, and is the same call trace. It seems that Normcore doesn't like this "nested" call to RequestOwnershipOfSelfAndChildren(), and it's why I'm seing it complain on HostSync, and not on PlayerSpawnPoses
the way I got rid of the error, was to not "nest" the calls to different realtimeView's RequestOwnershipOfSelfAndChildren()Glad you found a workaround. But yeah seems like a bug in Normcore, I'll log it internally