I am getting the error “Object reference not set to an instance of an object”. I don’t get it, surely myPos doesn’t need to be a reference to an object when I only want to assign a value to it from a Blackboard variable?
This is the code you posted for me in a thread below. I also did see a similar question where you advise GetComponent<Blackboard>() so I’m confused what is needed here.
Another point is that this is my Global Blackboard. The above code likely references the local?
The null reference is because the blackboard is not assigned a reference. Try this code bellow and please make sure that this script is attached to a gameobject that has a Blackboard component attached as well, since we assign the reference by GetComponent from this gameobject.
Sure 🙂
You can get the reference of a global blackboard with the static method GlobalBlackboard.Find(string name), where the parameter is the blackboard name. Here is an example:
1
2
3
4
5
6
7
8
9
10
publicclassExample:MonoBehaviour{
voidStart(){
varbb=GlobalBlackboard.Find("Global");
varmyPos=bb.GetValue<Vector3>("myPosition");
Debug.Log(myPos);
}
}
Let me know if this works for you.
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Author
Posts
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Login
Register
By registering on this website you agree to our Privacy Policy.