public class Agent : MonoBehaviour {
private FSM brain;
void Start ()
{
//Create the FSM that will control this agent
brain = new FSM (this);
}
}
public class FSM
{
//Agent this FSM is attached to
private Agent agent;
//Constructor
public FSM (Agent FSMOwner)
{
agent = FSMOwner;
Debug.Log (agent);
}
}
So I have an empty game object which has the Agent script on it. When the program starts, the Agent script instantiates a new FSM class. In the FSM constructor it debugs the agent, but it keeps returning null.
So how do I pass the Agent class to the FSM class so they can communicate with eachother?
I’d say it’s probably logging “True”. This would be expected. Unity overrides the implicit boolean operator to check for null in order to mimic the JS style of testing “does this thing exist”
@OP: that should work. What exactly are your errors? When are they thrown (if there’s errors thrown), where does null get debugged, when does this happen?