Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Need help with basic object spawning and understanding ownership (Netcode).

Discussion in 'Multiplayer' started by Blueprint_, Mar 8, 2022.

  1. Blueprint_

    Blueprint_

    Joined:
    Apr 15, 2021
    Posts:
    2
    Im completely lost and about to collapse. I've been looking at my screen for over 5 hours now, and can't understand anything.

    I made an empty object called EricSpawner. I added the Network Component and added it to Network prefabs.
    Its got this very simple script on it:
    Code (CSharp):
    1.     void FixedUpdate()
    2.     {
    3.      
    4.  
    5.         if (NetworkManager.Singleton.IsServer)
    6.         {
    7.             SpawnEricPrefab();
    8.         }
    9.         else
    10.         {
    11.             SpawnEricServerRpc();
    12.         }
    13.     }
    14.  
    15.  
    16.     void SpawnEricPrefab()
    17.     {
    18.         GameObject ericInst = Instantiate(ericPrefab, transform.position + new Vector3(Random.Range(-2f, 2f), Random.Range(-2f, 2f), 0f), Quaternion.identity);
    19.         ericInst.GetComponent<NetworkObject>().Spawn();
    20.     }
    21.  
    22.     [ServerRpc(RequireOwnership =false)]
    23.     void SpawnEricServerRpc(ServerRpcParams rpcParams = default)
    24.     {
    25.         SpawnEricPrefab();
    26.     }
    27.  
    The EricPrefab also has NetworkObject-Component and is added to Network Prefabs (Network manager).
    Upon playing (Either as Host or Server), My Hierarchy and Scene view is showing all the Eric's spawning, but none of them show in Gameview.

    I'm pretty certain this has something to do with ownerships (Which I have no clue how work, so if you know the basics, please explain), but I don't know.

    Pls Help, Im desperate.

    [SOLVED] Edit: Turns out, Z-axis of position made the Eric's invisible.
     
    Last edited: Mar 8, 2022
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    It sounds like the network side of spawning the objects is working correctly. How are you presenting them visually to the player?

    In basic terms ownership means either the server or the client has authority to make changes to the object and permission to make RPC calls. You can make RPC calls from client to server without ownership which is why RequireOwnership = false is used in your code above.
     
    JohnnyConnor likes this.