Parenting over the Network

I'm attempting to update a game object hierarchy over the network.

I have a game in which many game objects (space ships) can be linked up with each other in a variety of configurations through parenting. I can achieve parenting over the network via RPC, but once the hierarchy of objects changes, Photon stops tracking the movement of the parented ships.

How can I continue to track ships after their hierarchies have changed? Is this possible?




  • Tobias
    You will have to make sure each individual group has some kind of ID. You could possibly also use a PhotonView per group. When you rearrange groups, the ships should follow their current group and you might need to create new groups, too.
  • So you're saying if I leave the PhotonView on the root game object in a group, it should not break once the hierarchy below is modified?
  • Tobias
    If the PV affects the root object and the others follow, it should work, unless each sub-object has it's own PV and positioning.
    Not sure if that's what you want, as all position changes will affect the child objects directly. They follow in precisely the arranged positions they are in. If you want a fleet- / wing- like movement where individual ships smoothly follow each other, you will have to add some extra scripts to the child ships to achieve this.
  • So if I remove the PhotonView from the object before it becomes a part of a new hierarchy, the group PhotonView should track the addition of the child over the network? And continue to follow the group's position, even after the hierarchy has changed?

    Conversely, is it possible to add a PhotonView *after* an object has been instantiated? So basically an object with parent another, and then receive a brand new PhotonView which all computers in the network could track?

    Thanks for your help with this.
  • Tobias
    PhotonViews have a relationship to the object they got instantiated through and to that object's Instantiate call.
    Due to that it's a bit messy to remove individual PVs: The Instantiate call will also be removed from the cache!
    This means, it's better not to re-assign PVs.

    You could however spawn some groups with a PV on it and re-use those. Disable the groups you're not using and assign ships to groups as needed. You can "steer" and sync the groups as needed.

    Or: Use one PhotonView to send all updates through. Per Group, assign a id (a byte, e.g.) and you can easily send where a group is and what it does. It shouldn't be limiting you.

    > Conversely, is it possible to add a PhotonView *after* an object has been instantiated?
    Yes, that's possible as "Manual Instantiation". In this case, you get a PhotonView ID, send an RPC to instantiate and apply said view ID. This also doesn't have the problem that a Destroy(PhotonView) will remove a cached Instantiate of it's associated object.
    There's a paragraph about this in the package's PDF.

    Edit: I just threw options at you but didn't really provide guidance yet.
    I would probably try the "PV per group" approach or the "one PV for any group". The first makes more us if Unity's component approach and the latter puts a bit more control and coding work into your hands.