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

Question Networking issue with prefab spawning

Discussion in 'Netcode for GameObjects' started by noahyacowarforces, Aug 16, 2023.

  1. noahyacowarforces

    noahyacowarforces

    Joined:
    May 15, 2023
    Posts:
    1
    Hi all ! Below is an if statement I am having trouble understanding. I am trying to spawn prefabs over a network, and this client-RPC c is supposed to add the objects into a scriptable object "triggerSE" for spawning. When trying, one prefab is working, but I cannot seem to replicate it.

    I am not all sure what TryGet is even doing, even after consoling the documentation. Maybe an explanation of what it is doing would help me.

    The issue is the if statement comes as false for all but one prefab.

    I am a newbie, apologies for any newbie lingo.

    Code (CSharp):
    1. [ClientRpc]
    2. public void AddTriggerClientRpc(NetworkObjectReference networkObjectReference)
    3. {  
    4.     if (networkObjectReference.TryGet(out NetworkObject obj))  
    5.     {    
    6.          triggerSE.AddElement(obj.gameObject);  
    7.     }
    8. }
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Does all your prefabs have a network object component?