Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to parent and network object a grandchildren that doesnt have network object

Discussion in 'Netcode for GameObjects' started by firebird721, May 14, 2023.

  1. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    Lets say i have a network object player which has a child named,lets say, a laser gun(at this stage he doesnt have network object attached) and i want to connect to the gun a laser prefab(which has a network object attached) this laser prefab should be attached to this small hirrachy as in

    player
    laser gun
    laser

    ofcourse during game player can switch laser guns and lasers so should ne able to destroy them and build and reconnect them

    what is the official or best way to do it?
    thx!
     
  2. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    Thx for the reply but The questions is about spawning in running time and in multyplayer netcode formation
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    The easiest way is to build an all-encompassing prefab that contains all switchable variations rather than dealing with the difficulties of network-parenting and its unnecessary overhead when there's a simpler alternative.

    For example:
    Player
    - Weapons
    -- RocketLauncher (inactive)
    -- LaserGun (active)
    -- PlasmaRifle (inactive)
    -- ChickenTransmuter (inactive)
    -- etc.

    And then just enable/disable these game objects (or components) as the player switches weapons. You can do weapon upgrades in a similar fashion.
     
    Last edited: May 14, 2023
    firebird721 likes this.
  4. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101


    thx allot!
    i used some of this suggestions already and it helped

    Its good cut around but srill i would like to see how the best way to deal with it if we are trying to parent and all this mess..

    hope someone will know how can it be done easily
     
  5. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    278
    This resolved Github Issue walks a user through one way to attach an object picked up to an owner/client authoritative (NetworkTransform) player. CodeSmile's approach is another recommended path to take.
     
    firebird721 likes this.