Search Unity

IsOwner property not recognised in script

Discussion in 'Netcode for GameObjects' started by Josh65, Mar 6, 2022.

  1. Josh65

    Josh65

    Joined:
    Jul 5, 2020
    Posts:
    13
    I get "The name 'IsOwner' does not exist in the current context" when using it. Using NetworkObject.IsOwner i get "An object reference is required for the non-static field, method, or property 'NetworkObject.IsOwner'" but VS will find it as a bool correctly.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Netcode;
    5.  
    6. public class NewBehaviourScript : MonoBehaviour {
    7.     void Update() {
    8.         if (IsOwner) {
    9.             Debug.Log("Owner");
    10.         }
    11.     }
    12. }
    Im using unity 2020.3.27 and network objects for gameobjects 1 pre 5
     
    Last edited: Mar 6, 2022
  2. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    492
    You have a Monobehaviour that is trying to access something that is only available in the NetworkObject class. Because the field is not static but is different for every gameobject with a NetworkObject script, you need to inherit from a different class like NetworkBehaviour (which also has this) or attach a NetworkObject script and get this component.