-
Notifications
You must be signed in to change notification settings - Fork 449
Support spawning a prefab of a NetworkObject that has child NetworkObjects (make re-parenting more consistent in Netcode projects) #2700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
^ this tbh |
Yes I need this too. I am making a simple VR multiplayer game. I need to parent objects to the hands when the player picks something up. I could spawn the hands separately but that complicates everything. Right now I have my own parenting system but it's far from perfect. Netcode for GameObjects recently got a lot of improvements to parenting. This is the only thing that's missing for me. |
Hey, it seems that the fix was included in #3013, can you confirm it? Otherwise I will be closing this thread soon-ish |
@michalChrobot |
Aa, ok, thanks for the information! I will try to follow up on this then |
Please. This is a long overdue feature. It's the biggest pain point of netcode for gameobjects. It should be available on the first version. I don't understand how this is not a priority. |
Just following up regarding network prefabs with nested NetworkObjects. The primary issue involved with this has to do with "network prefabs" being associated with a NetworkObject's A NetworkObject really has a few primary functions:
Other than this, all of the real "netcode" is handled in The primary voiced opinion is that it would simplify parenting of The answer to the second part above is that having several
So, this lands us back to what are the benefits of having "complex" network prefabs where there are multiple Parenting NetworkObjects (Uses/Benefits) What do we mean by "useful"? If you have a vehicle that you want to start a player within upon first spawning, this would be "useful" but is it really needed? When a
Where some of the If you wanted to remove the player from the vehicle you would:
Now a player's input is controlling the player and the player is no longer parented under the Root. Of course, today you would have to write your own components that use NetworkVariables that track where each child is parented.
Then you would need to make any late joining players check those references to determine if the Children are still under their default parent, have no parent, or are parented under something else. Of course, upon despawning all children would make sure they were parented under their original parent. The message routing for a player that "got out of their vehicle" would still work...you could chose to change the Of course, if the player's vehicle could be destroyed then this makes no sense...and under that scenario you would want two unique network prefabs... a Player and a Vehicle and would just want to spawn both at the same time (i.e. the player could point to their Vehicle which would automatically spawn it and parent the player under it). However, the big take away is that you can also have things like: A weapon item: that can be in-scene placed or randomly spawned at different locations:
The player:
The player (only a small portion...I gave it no head or legs..) is just laid out in a normal fashion with a position to attach a weapon or item being carried. To "pickup" the weapon you can opt to parent the entire Root "Weapon Item" =or= you can simply use the same technique described earlier and just parent the Weapon Item's Child-A under the Player's Child-E (normal unity parenting) with (of course) some form of component or added script that handles setting the Weapon's Child-A GameObject to having been parented under the Player's Child-E (i.e. so late joining clients would synchronize based on the NetworkVariable's set value when spawning the weapon item and the player. Using NetworkObject parenting today is the "easiest" but can result in issues with things like handling smooth transitions between parenting and making sure the NetworkTransform's synchronize (all can take time sorting out that side of things) =or= you can use the "Child with NetworkBehaviours" approch but that requires you to write the additional script to handle the assignment of the parented NetworkBehaviour and assure late joining clients properly synchronize... both have pro's and con's... With this said... the "rules" behind parenting a "Child of a spawned network prefab instance" are that it requires tracking "who its parent is"... but nothing else...it uses standard unity parenting...and can make it less complicated in regards to NetworkTransform since the Weapon's Child-A would have no NetworkTransform... it would just synchronize to the player's hand's motion. The rules behind NetworkObject parenting...well.. it requires you parent directly under another NetworkObject and there are additional complexities there. So, our near future plan is to provide a component that automatically handles the "Child with NetworkBehaviour(s)" parenting side of things (well it will provide the basic aspects of it with the ability to make your own version for custom solutions) which (I believe) will be a better "fix" for the issue behind not begin able to have "complex network prefabs". When will this component be avaiable? As soon as possible...but we also want to address other foundational issues in NGO (v2.3.0 contains some improvements to the BufferedLinearInterpolator which provides you with two new interpolation types and the ability to modify aspects of them via NetworkTransform). But... we are primarily focused on providing an over-all continually improved netcode development experience...and have not forgotten about this specific user pain (and are taking actions to provide something that, we believe, will yield a better over-all result for everyone). |
It's possible to have scene objects where a parent NetworkObject has children that are also NetworkObjects. This is particularly notable, because it allows you to re-parent some other NetworkObject onto that nested child NetworkObject in the scene.
When you spawn a prefab of a NetworkObject into the scene, you can only re-parent to the top level of that spawned NetworkObject -- the GameObject that directly has a NetworkObject component -- but none of its children.
This leads to us programmers having to deal with potentially two different code pathways for when a prefab was placed in a scene vs when a prefab was spawned. In some cases we may even have to split prefabs because of this... one that can be placed in scenes and one that can be spawned.
Besides the re-parenting use case, this limitation also gets in the way of modular/nested prefabs in your project. You cannot have a re-usable nested prefab module that is itself spawnable, because then you would not be able to use it on any prefabs that are spawnable themselves.
The text was updated successfully, but these errors were encountered: