How can i give child objects a script with NetworkBehaviour when the parent of the child has a networkIdentity, but you can’t have 2 network identity’s on the same player as stated here:
https://docs.unity3d.com/ScriptReference/Networking.NetworkIdentity.html
Option one:
Spawn the child objects with autority when you spawn the player.
Option two:
Do the logic on the object and have like a Cmd manager on the root where you actually send your Command’s.
For option 1 does checking a child objects local player authority allow the player to have more then 2 network identities or something? And for option 2 i would like to avoid that because i originally designed the game for single player but now i’m upgrading to multiplayer and lot’s of the games code relies on scripts being managed in the child objects.
Uhm. Ye. Just tick the local player authority. And when they spawn. Use NetworkServer.SpawnWithAuthority.
I seem to have a further problem with this setup, maybe i should describe the situation further, the game objects that i’m trying to spawn as children are weapons that that player can equip. Each weapon object has a weapon script which shoots a projectile if it’s the localPlayer but the network identities netId on child objects are different from the parents netId, do you have any suggestions for this?
I had the same setup. On your weaponscript. Replace isLocalPlayer with hasAuthority
Nice, it worked thanks for the help.
Also this is not related to the original issue but when i spawn object with a networkIdentity specifically bullets i noticed that the netId goes up really high even though they are deleted, is there a way to reset the netId count or does it not really matter?
That’s internal of the HLAPI. Pool the bullets instead. Or dont have network identities on them
how high? in my experience, the net id’s just increment one by one for each object. if you see it jumping unusually high, you might be (inadvertently?) spawning way more things than you intended.
you shouldn’t need to worry about the net id getting too high i’d think. it’s a uint, so you can have billions of network identities co-existing before you have a conflict.
Also do you know how to sync an array of integers like the SyncVar Attribute, because my players inventory is stored in an array of id’s, I’ve been researching for hours and cant find any answers anywhere.
I should let you know that this is probably my last question so that you don’t think i’m gonna keep posting in here all the time whenever i have a problem.