Search Unity

Proper method for Server Spawning nested RigidBody Prefab.

Discussion in 'Multiplayer' started by RedRiverStudio, May 26, 2017.

  1. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    What is best method to spawn a single prefab that contains several other small rigidbody objects and have them linked on all clients? I can currently spawn a prefab, which instantiates the children, but each requires a manual "spawn" button to do... something. They do show up on the client side, but nothing is syched despite the server reporting all objects as having net ID numbers, isServer, isClient, hasAuthority.

    This is an identical issue as the following topic and answer:
    https://forum.unity3d.com/threads/c...-prefab-with-a-bunch-of-child-prefabs.352555/
    http://answers.unity3d.com/questions/1035717/unet-networkspawn-and-child-objects.html#answer-1038583

    The answer was from a couple years ago, so is this still the case?

    Thanks,
    Ryan
     
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I do not know if there is an easy way. I *think* all NetworkBehaviour scripts must be in the root of the object along with the NetworkIdentity.

    Are you planning on detaching the child networked objects, or will they always remain attached?
     
    RedRiverStudio likes this.
  3. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    The idea was to spawn a prefab full of "debris" rigidbody objects, all children of the host empty GameObject, but free to move about the scene independently.

    It really looks like the network manager wants to synch all of them when spawned,but it is just missing some final step. Is there a way to manually tie the objects together across the net after the prefab is spawned, or is there no genuine connection between server and host?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'd look at NetworkTransformChild to see if that works for you. You put them on your root gameobject and point them to your child objects. You also need a NetworkTransform on the root gameobject.

    https://docs.unity3d.com/Manual/class-NetworkTransformChild.html

    What I would probably do is instantiate them separately though. I'm not sure what you mean by having to manually press a spawn button. You should be able to get around that.
     
  5. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    I did have a poke, but it seems to only be for a single child object, and that child object doesn't have a NetworkTransform attached to it. It's such a specific component I am really curious why it was created.

    I might concede failure for this one and rethink my prefab system... again.
     
  6. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    Are the rigidbody shrapnel pieces that break off just for visual effect, or do they need to be synchronized? If they don't need to be synchronized then you could possibly let the object explode and throw shrapnel everywhere but it would be different on each client.
     
  7. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    There were meant to be all synced physics objects. Good example would be a crumbling low wall, full of loose bricks that can be blasted or run through by players, but spawned as a single object. The bricks are large enough to be carried around and used as shields.