- Home /
Question by
Holmqvist · Sep 29, 2019 at 03:35 PM ·
getcomponentnull
Referenced object child is null, but isn't null internally
(Impossible format correctly, I apologize)
NPC.enemyTarget is not null
FSM holds a reference to NPC called _npc, it is not null
_npc.enemyTarget is somehow null
public class NpcCombat : MonoBehaviour, IIK { ... public LivingEntity enemyTarget; // Assigned in Unity, not null! }
public class GetCoverState : AbstractFsmState { ... public override bool EnterState() { ... var npcCombat = _npc.GetComponent<NpcCombat>(); // Not null, implements LivingBeing if (npcCombat && npcCombat.enemyTarget) //enemyTarget is null somehow ... } }
It's not a race condition, as I've used IEnumerators to delay GetComponent when debugging. All references are met, and are not null when Debug.Logging, except when the stucture is parent.parent.child.
Comment
Your answer

Follow this Question
Related Questions
How do I determine the presence of a script on an object? 1 Answer
Why is this null? Finding a script on an object 3 Answers
GetComponent hates me 2 Answers
get component null reference 2 Answers