Search Unity

How can i give child objects network functionality with the HLAPI?

Discussion in 'Multiplayer' started by Epic-Username, Jul 27, 2017.

  1. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    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.
     
  3. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    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.
     
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Uhm. Ye. Just tick the local player authority. And when they spawn. Use NetworkServer.SpawnWithAuthority.
     
  5. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    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?
     
  6. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    I had the same setup. On your weaponscript. Replace isLocalPlayer with hasAuthority
     
  7. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    Nice, it worked thanks for the help.
     
  8. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    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?
     
  9. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    That's internal of the HLAPI. Pool the bullets instead. Or dont have network identities on them
     
  10. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    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.
     
  11. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    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.