SharedGameObject can't access components with GetComponent

Pietrofonix

New member
Hi guys, I need help with the Shared Variables. I created a Global Variable of type GameObject in a Behaviour Tree called "AudioObjectDetected" and I want to assign it to a SharedGameObject variable that I created inside a Node.

public class BDFaceObject : Action { public SharedGameObject runtimeFaceObject; public override void OnStart() { runtimeFaceObject = (SharedGameObject)GlobalVariables.Instance.GetVariable("AudioObjectDetected"); base.OnStart(); } public override TaskStatus OnUpdate() { AC.Hotspot faceObjectHotspot = runtimeFaceObject.Value.GetComponent<AC.Hotspot>(); } }

In the example above I'm trying to access to the AC.Hotspot component by using "runtimeFaceObject.Value.GetComponent", but Unity gives me the error "Object reference not set to an instance of an object". If I use the normal type GameObject It works perfectly. Do you know why SharedVariables can't access components with Value.GetComponent?
 
Last edited:
Does runtimeFraceObject.Value return a non-null reference? My guess is that this is a null value.
Oh yes, I'm such a fool, It was so easy the solution. Basically I forgot that the global variable "AudioObjectDetected" was null, and when I was tryng to assign the variable runtimeFaceObject to It inside Start, Unity couldn't find anything. I had to comment the line "runtimeFaceObject = (SharedGameObject)GlobalVariables.Instance.GetVariable("AudioObjectDetected");" or put it inside a "If" to check for a specific condition when to assign It. Thank you for the answer ?
 
Top