BeardedManStudios / ForgeNetworkingRemastered

See various forks, also please join the Forge Community fork of Forge Alloy! -> https://github.com/ForgeAlloyCommunity/ForgeAlloy
https://twitter.com/FarrisFaulds
Apache License 2.0
1.49k stars 305 forks source link

Client in the objectCreated handler, getting a null AttachedBehavior #371

Open Gwom opened 4 years ago

Gwom commented 4 years ago

Version Number and Operating System(s):

03/10/2018-19.53.38,04 Windows, Unity Editor 2019.2.21f1

Expected behavior:

objectCreated should be called after the AttachedBehaviour's GameObject is Setup / Passed Start() / NetworkStart(), if not, add a callback that is at this point and rename ObjectCreated - it may just be me but I assumed this should be done by the time this is called, maybe it is a naming issue. Even more ideal would be to have something in the objectCreated callback where you could access the GO without having to typecast as this would be useful!

Actual behavior:

For the Client, I found NetworkStart is called after the objectCreated callback, leading to the AttachedBehaviour to be null.

Steps to reproduce:

[Optional] Discord Username:

Gwom

Gwom commented 4 years ago

Info from @phalasz is that the objectCreated listener is also used for the NetworkBind function, so AttachedBahaviour may not be there already. Would it be possible to ensure when the NetworkBind is added to the listeners it is put at the front, something like make a new listener, add NetworkBind, and the old listeners, hopefully ensuring that the users callbacks happen after NetworkBind does.

Either that, or add a different named listener for the NetworkBind to use, that happens before the objectCreated listener

Failing any of these, maybe re-name the listener to "objectCreating" and update the documents to state that the AttachedBehaviour maybe null if the NetworkBind has not happened, and to use the NetworkStart if you need to ensure it is a GameObject.