Here is my action task. I have a separate method to EndAction that I want to call in a different script that looks like this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System.Collections;
using System.Collections.Generic;
using NodeCanvas.Framework;
using NodeCanvas.Tasks.Actions;
using UnityEngine;
publicclassEndAction:MonoBehaviour{
publicRequestInputField testbuttonscript;
publicvoidMoveOn(){
testbuttonscript.OnInputFieldFills();
}
}
I keep getting that Null reference exception, so I guess my question is, how do I reference the action I want to end, if EndAction() only takes a bool?
I think it would be better if you try to achieve what you want by using some sort of static events, in which the ActionTask can subscribe to instead of trying to get a reference to the action task object itself.
Here is a very rough example of what I mean:
1
2
3
4
5
6
7
8
9
10
11
12
publicclassExample:MonoBehaviour{
publicstaticevent Action onMoveOn;
publicstaticvoidMoveOn(){
if(onMoveOn!=null){
onMoveOn();
}
}
}
You could also turn the above example into some kind of a “manager” if you’d like.
Then in your action tasks, you could subscribe to the event in the OnExecute method like this:
1
2
3
Example.onMoveOn+=()=>{EndAction();}
This way, and by using events in general, you don’t have to worry about referencing everything. 🙂