0

So I've been making this online survival game using mirror and I have come across an issue with spawning in a weapon for the player.

Apparently you can only parent an object to another networked object (when executed by the server).

When I was doing this in single player I had no issues obviously as I could just set the parent to my camera holder game object and it will follow the cameras rotations as expected.

Now for the client to see the other players spawned equippable, I can only seem to set the parent of the equippable to the player transform where the network Identity/transform is.

If I go to set it to the camera holder then nothing happens, the equippable will just spawn in at 0,0,0.

So with this said, is this the only way to do this? Have a ClientRpc tell the client to parent the equippable to the root of the player and then have code on the equippable to follow the camera?

I feel like I'm missing something important as this method seems quite finniky.

Thanks in advance.

I have tried putting another network transform on the gameobject I would like the parent to be set.. mirror doesn't like this, was hoping it would parent but it just goes to 0,0,0

I have tried to code moving the equippable with the camera but I wasn't getting good results so I thought I would ask here if there was a much easier and or practical way to execute this.

  • parenting is always kind of an issue in networked code ... you will have to make sure the object has actually already been spawned on all clients before they receive the RCP to parent it - not sure if Photon mabye already does this - then once this is the case passing on the two NetworkObject IDs should be enough so both the child and parent object can be identified. And then you will need to also store it so that later joining clients can also do the parenting as soon as both objects are spawned for them locally – derHugo Jan 31 '23 at 12:27
  • Would you say it would be better to just go the other method being: have the items already on the player and just have them set active(true/false)? I wonder how other people have gone about this.. – Skourge Jan 31 '23 at 12:47
  • depending on he amount of objects etc this might be a simple good approach indeed. I would probably still go through prefabs, just that instead of network spawning them I would only synchronize a "state" meaning e.g. "player A is currently holding an XY" and then each local representation on each client is responsible to go into that state and spawn/destroy the according visuals. I hope that makes sense somehow ^^ – derHugo Jan 31 '23 at 13:06
  • Yep that makes sense, I'll give that a go! I'll have to look into how to code it. – Skourge Jan 31 '23 at 13:14
  • Also! Just found a gem of a video of a person explaining the same problem and apparently the "official way" to parent something is to use a network wrapper, so the network wrapper game object will have the network ID and network transform and the child will be say, an axe. Have the network wrapper take the child axe and set it to the players wield point game object respectively. Then, just destroy the network wrapper. – Skourge Jan 31 '23 at 13:17
  • that also sounds great! A final stupid approach would have been to instead of using parenting at all simply make the spawned object copy the transformations of the "parent" object ... still yours and this would require to identify the target "parent" object on the clients though – derHugo Jan 31 '23 at 13:22
  • Yeah I'm sure I would have tried that as a last resort probably lol. I Appreciate your time, have a good one :) – Skourge Jan 31 '23 at 13:31

0 Answers0