Hello,
So my problem probably has a simple answer, but I’ve been staring at the code so long the words have lost all meaning.
Please consider the following code block:
[ClientRpc]
public void RpcAreaScan() // Uses a Physics.OverlapSphere to scan the area up to this entity's Awareness Max Distance and log any GameObjects on Layers specified in the LayerMask
{
Collider[] localEnts = Physics.OverlapSphere(this.transform.position, MAX_DIST, mask);
if(localEnts != null && localEnts.Length > 0)
{
foreach(Collider col in localEnts)
{
Stats tempStats = col.gameObject.GetComponent<Stats>();
if(tempStats != null)
{
if(tempStats.GetName() != entStats.GetName()) // NPCs aren't worried about same species... for now.
{
if(!trackBook.Contains(col.gameObject))
trackBook.Add(col.gameObject);
}
}
else
Debug.LogWarning(this.gameObject + " RpcAreaScan(): Error fetching the Stats script for a detected entity, can't add to trackBook");
}
}
}
This is called on NPCs during their FixedUpdate as a part of a larger routine where they check their vicinity up to MAX_DIST for potential targets. They’re specifically searching for a script, Stats, on the detected entity. This serves as a little check as well, in case they detect something unexpected that they shouldn’t have. (Maybe I forgot to put a detail GameObject on the right layer, or some such. Don’t want NPCs staring at flowers.)
Stats is a NetworkBehaviour derived class that stores key info like the NPCs name (species), health, damage output, etc.
Anyways, the player object has a Stats script, right there on the root GameObject. And yet the NPCs can’t seem to find it. When I walk within range, I get spammed with that LogWarning at the bottom. I can’t figure out for the life of me why they can’t see the Stats script, so I have come to the community for aid.
Thanks for your time!