Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Nested networkBehaviors not instantiating correctly on client #173

Open
Karmelov opened this issue Aug 11, 2018 · 4 comments
Open

Nested networkBehaviors not instantiating correctly on client #173

Karmelov opened this issue Aug 11, 2018 · 4 comments
Labels

Comments

@Karmelov
Copy link
Contributor

Karmelov commented Aug 11, 2018

When you have a NetworkBehavior which has children with other NetworkBehaviors, there is a chance the children are not initiated correctly.

This issue only happens when the function NetworkManager.CaptureObjects(NetworkObject obj) process the children before their parent. For some reason this seems to be an issue for new connecting players, when they receive all the created instances at the same time.

When the parent is processed first

  • The parent NetworkObject is processed in the NetworkManager.CaptureObjects function and a new instance is created for its NetworkBehavior. When its NetworkBehavior is initialized, it adds its children NetworkBehavior to the NetworkBehavior.skipAttachIds static dictionary (which is done in the NetworkBehavior.ProcessOthers function)

  • When the children NetworkObject are processed in the NetworkManager.Capture they find themselves on the skipAttachIds dictionary, attaching the networkObject to the already instantiated NetworkBehavior.

When the children is processed first

  • The children NetworkObject is processed in the NetworkManager.CaptureObjects function and a new instance is created for its NetworkBehavior. The NetworkObject is now part of this new NetworkBehavior instance.

  • The parent NetworkObject is processed in the NetworkManager.Capture function and a new instance is created for its NetworkBehavior. When its NetworkBehavior is initialized, it adds its children NetworkBehavior to the skipAttachIds (which is done in the NetworkBehavior.ProcessOthers function)

  • The children NetworkBehavior are left without a NetworkObject, and the skipAttachIds is left with the children's NetworkBehavior inside.

Possible solution

There should be a way to guarantee that the NetworkObjects are processed by the NetworkManager.CaptureObjects in a way that the parents are processed first.
I'm not 100% sure about this, but I think this depends on the order in which the NetworkObjects are stored in the NetWorked.pendingCreates when the NetWorked.Flush() function is called.

@mcguinnessdr
Copy link
Collaborator

@Karmelov Has this been fixed in the recent commits?

@artfabrique
Copy link

Does the fix is on a roadmap already? Or we just have to avoid nested NBs?

@phalasz
Copy link
Contributor

phalasz commented Apr 17, 2019

@Karmelov do you have a small project that reliably reproduces this issue?

@phalasz
Copy link
Contributor

phalasz commented Jun 23, 2019

Could someone check whether PR #270 fixes this as well?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants