Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request Parenting a networkobject be allowed when rootparent is networkobject and direct parent is not

Discussion in 'Netcode for GameObjects' started by liambilly, Feb 17, 2023.

  1. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    when i enable or diable a gameobject this information is not being correctly synched that only the client who disabled or enabled the object can see this information, how would i go about this to make if i disable it wont be visible for anyone and if i enable it it becames visble again for everyone,
    this object has a monobehavior
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    226
    Maybe call a clientRPC to dissable/enable the object for all players?
     
  3. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    a clientRpc can only be calledby the server
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    437
    But you can call a ServerRPC from the client to do the opposite!
     
  5. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    so i should do a
    cllientrpc inside of a serverrpc
     
    lavagoatGG likes this.
  6. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    this method works only for networkbehaviors with a networkobject bt not for a monobehavior
     
  7. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    i would change my script to a network behavior but the problem is this object i want to synchronize its active state,i have to parent it and we know parenting on networkobjects is tricky,


    so isnt there a way to synch a monobehavior active stave?
     
  8. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    226
    You can call clientRPC on another script that is network behavior and in it find ans disable the objects you need
     
  9. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    i mean the object im trying to set the active state,has a monobehavior, im trying to set its activity from a network behavior but apperently its not possible since it doesnt have a networkobject
    . i tried to do the same with a test game object that has a networkobject, that test worked,
    but adding a network object to the object im trying to set it activity will be out of the question for me since im using has some rigs that will control the objects aim n position n that must be under the animator, n network objects come with other parenting issues since im not parenting it directly under the player root
     
    Last edited: Feb 18, 2023
  10. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    heres also an answer ive gotten from from OpenAI.


    [[MY QUESTION: what if the weapon doesnt have a network object will this active information be synched

    OPENAI: If the weapon game object doesn't have a NetworkIdentity component attached to it, then the OnTriggerEnter method in the example script will only be called on the local client that triggered the collider, and the SetActive(false) call will only disable the weapon object on that client. The state of the weapon object won't be synchronized across the network to other clients, so they won't be able to see that the weapon has been picked up.

    To synchronize the state of the weapon object across the network, you'll need to attach a NetworkIdentity component to it and spawn it using the NetworkServer.Spawn method.]]


    i also read unitys parenting doc my issue is like the player tryin to parent under a certain car seat, bt still i cant spawn parts of player and reparent them on spawn especially since they depend on rigs ,i think this issue is hopeless for now
     
    Last edited: Feb 18, 2023
  11. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    [THE FEATURE REQUEST]
    so id request unity to incoporate a way to parent network objects under non networkobject saying as long as the root of that parent has a network object

    OR

    a way to synchronize active states of a non network objects to all clients
     
  12. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    437
    @liambilly Have you already had a look at the examples in the official ClientDriven sample?

    If not, you can download it here.

    Its examples show how to use the third person controller asset in a multiplayer environment for movement and picking objects up
     
  13. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    yes ive had a look at it, the player is parenting those networkobjects directly below him not to any of his children. it would be better for unity to allow parenting network objects just looking at the root instead of parent
     
  14. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    437
    @liambilly Would it be possible for you to open a feature request here? In this way, the team behind Netcode For GameObject will be able to prioritize your features, and you'll be automatically updated about their status
     
  15. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    128
    RikuTheFuffs-U likes this.
  16. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    437
    @liambilly thanks! I see that one of the devs provided a very detailed answer there, did you manage to try it out?
     
  17. MrBigly

    MrBigly

    Joined:
    Oct 30, 2017
    Posts:
    221
    RikuTheFuffs-U likes this.
  18. MrBigly

    MrBigly

    Joined:
    Oct 30, 2017
    Posts:
    221
    This problem has been rolling around the back of my mind quite a bit.

    In the document @RikuTheFuffs-U pointed us to, it shows a use case with a vehicle example. Unity says that best practice is that the seats need to be removed from the vehicle prefab and spawned as separate prefabs, then parented to the vehicle. But this assumes that they require Network Objects to parent the pawn to them if NGO is to replicate the parenting.

    Let's say that the seats don't have a NO on them and they remain part of the vehicle prefab. When the server decides to mount the pawn onto a seat, let's say the vehicle has a mounting script that is used for this purpose. Let's say that this script parents the pawn to the seat that it is closest to. Now we have the following tree:

    Vehicle - NO
    + Seat
    + Seat
    + pawn - NO​

    Can the vehicle script simply parent the pawn to the seat by something like the following line of code?

    Code (CSharp):
    1. pawn.transform.parent = this.seat[n].transform;
    If so, what is sent across the wire when this happens? If nothing, then the script could RPC the clients to parent the pawn to seat[n], yes?