private MonsterPathJumps monsterPathJumps;
// Use this for initialization
public new void Start () {
base.Start();
monsterPathJumps = GetComponent<MonsterPathJumps>();
if (monsterPathJumps == null) Debug.Log("MonsterPathJump NULL");
monsterPathJumps.SetCollider(bodyCollider);
if (monsterPathJumps == null) Debug.Log("MonsterPathJump NULL");
}
When this code runs, I get the first log entry MonsterPathJump NULL
Then I get
NullReferenceException: Object reference not set to an instance of an object
Spring.Start () (at Assets/Scripts/Monsters/Spring.cs:19)
which points to this line:
monsterPathJumps.SetCollider(bodyCollider);
Yet the code inside SetCollider is executed, and I do not get the second MonsterPathJump NULL log.
the bodyCollider is not null, it is set in the base.Start() call and I’ve tested it.
Every component is in the same GameObject
Do I need to have wait time after GetComponent to be sure it’s loaded? Should I put all my GetComponent calls in Awake()? Is there something else I am missing?
Thanks!