Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Feedback network objects isowner is true. in script I cant use isowner or any networkobject variable.

Discussion in 'Netcode for GameObjects' started by treydarling, Aug 8, 2023.

  1. treydarling

    treydarling

    Joined:
    Oct 25, 2015
    Posts:
    2
    is owner works on player objects. the script is a network behavior rather than a monobehavior. this returns false even though I can see its true in the network object.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5. using Unity.Netcode;
    6.  
    7. public class Shoot : NetworkBehaviour
    8. {
    9.      void Update()
    10.      {
    11.  
    12.             Debug.Log(IsOwnedByServer);
    13.       }  
    14.  
    15. }
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    612
    In quick testing it's showing as true, although an in-scene object may initially be false. How are you spawning Shoot?
     
  3. Zaba_Dev

    Zaba_Dev

    Joined:
    Feb 27, 2018
    Posts:
    11
    For me, using AddComponent made IsOwner not work. NetworkObject.IsOwner returns true but IsOwner returns false. So I guess use NetworkObject.IsOwner.

    Edit: Nevermind, it seems [ServerRpc] doesn't work if not the host since it believes it's not the owner, so I assume that's using IsOwner. You could use [ServerRpc
    (RequireOwnership = false)] but I get the feeling there'll just be more problems, so for now from what I can tell AddComponent just doesn't work with NetworkBehaviours.
     
    Last edited: Oct 30, 2023