Get isLocalPlayer in child object

So, I have a child object that has some code that needs to access isLocalPlayer. The parent is the one with the network identity, so I cannot access the isLocalPlayer variable directly. I made a script attached to the player that will store the isLocalPlayer variable, and the child can access it by using GetComponent. However, that is being called every update, and I’m sure that so many GetComponent calls per update will cause some kind of overhead. Is there any other way to check and see isLocalPlayer without so many calls?

Cache the reference to the script instead. Anyway, you can access the isLocalPlayer variable through the NetworkIdentity on the parent object since NetworkBehaviour.isLocalPlayer is just a property calling NetworkIdentity.IsLocalPlayer.

NetworkIdentity netview;

void Start() {
  netview = GetComponentInParent<NetworkIdentity>();
}

void Update() {
  if(netview != null && netview.isLocalPlayer) {
    //Do Something
  }
}

Caching was probably first thing I did, however it did not work, since it made everyone a localplayer even if the player object did not belong to them. I also got the parent NetworkIdentity variable, but it produced the same result. I have a workaround in mind, so I will try that and see if that works whenever I get back.

I reloaded my scripts, and now it somehow works. Thanks.