- Home /
Network Objects given the wrong position
When I instantiate an object with this code:
if(Inv[i] != NewItem){
NewItem = Network.Instantiate(Inv[i], hand.position, Quaternion.identity, 0);
}
NewItem.transform.parent = hand;
NewItem.transform.rotation = hand.transform.rotation;
The client that is instantiating NewItem properly receives the position/fact that it is parented but all the other clients only see the NewItem for a split second at its assigned position and then NewItem's position is set at 0,0,0. Part of me feels that I need to us NetworkOnSerialize or an RPC call to update the parent but i also feel like if I can avoid spending hours on those functions and realizing it's something client side is a good idea (the amount of hours I've wasted on NetworkOnSerialize is just sad).
Thanks for any response I'm open to them all.
First off, is that code in an RPC call? If not, it should be. Second, is there any code that moves NewItem around besides this one?
Answer by Bunny83 · Jul 28, 2012 at 03:33 AM
Do you parent the object on the other clients? i guess not. when you parent an object, that action isn't synchronised because that's even not possible / or very hard to achive automatically. Each client has it's own set of gameobjects. The only connection between a GO on your PC and a GO on another PC is the NetworkView. If they have the same ID they are "linked" together. The only thing that is synced is the local position and rotation. You actually don't need a NetworkView on the item when it's not moving on it's own.
You usually would send an RPC that tells everyone that you want to attach the object to your hand. I can't be much more specific since the actual process depends on your setup. How you can identify your objects / players on each client and so on.
It worked thank you so much for the quick response you saved me so much time it isn't even funny.