- Home /
Trigger reference problem
My bus goes to trigger and I get null reference exception problem on this script.
I want a move passenger in trigger enter.
So how I do this ?
*
Answer by tormentoarmagedoom · Apr 11, 2018 at 08:14 AM
Good day.
I was writing your answer in the last post, but you changed it and now have to write all again... :(
null reference exception means there is a variable that is not assigned when trying to execute that line. So if the problem is in the image line, most probably the boject containing this script, does not have the component passangermove so when try to find it gives you the error. You see you are not looking for the PAssangerMove in the bus right? you are looking inside the same GameObject that contains this script. To acces the bus you need:
other.GetComponent<PassangerMove>().....
A good practice is to use
Debug.Log(SomeVariable);
just the line before of the problematic line to see whats the state of the variable.
Other important thing. Is NOT a good practice to enable/disable scripts. Is beter to have the script always enabled, and change some variable when needed (like a bool) to allow the script do something.
If helped, accept the answer! If need more help, give more info!
thanks for message but my problem doest not fixed. :(
As I said, you first need to detect which variable is not assigned when trying to execute.
And then discover why is not assigned. We can assume the OnTriggerEnter is executing, right? so the problem must be inside. With the info you gave, we can not help more. Give more info, paste all error text.