Can't assign variables to collided object with Physics.OverlapSphere

Hi everyone,

I am having a tough time assigning variables through Physics.OverlapSphere.

The code is detecting the objects correctly through the tags and layers system, but for some reason I cannot assign a variable to the objects the cast is colliding with, see my code attached.

The object I am trying to assign the variable to has the variable set to pubic, so I really don’t understand why it just wont assign the transform correctly. No errors in my compile, but as soon as I try trigger it in-game it says “Object reference not set to an instance of an object”.

Any suggestions?

Thank you in advance.

Perhaps one of the objects with the tag “NPC” that the OverlapSphere detected does not have a “scr_NPC_AI” component attached to it?

Oh my word, stupid error.

I had the “NPC” tag on both the child and parent layers. You were correct, as the object it was detecting did not have that script, but the parent did.

Thank you!