SimplePath instantiated AI

I just purchased SimplePath from the Unity asset store and I’ve hit a snag: When instantiating an enemy who has a PathAgentComponent I am immediately setting the m_pathManager to the scene’s PathManager but still getting errors and no pathing behavior. The pathing works great if the enemy already exists in the editor but I’m having trouble getting enemies instantiated at runtime to work. Is there a solution to this?


#edit

Since SimplePath is a system I paid for I don’t think I’m allowed to post the code here but I think the root of the issue is needing to set a property on a behaviour after instantiation but before Awake is called. Is that possible or is there a common approach for this type of issue that I am just unfamiliar with?

I’m pretty sure you can’t do something before Awake - however, how about you get the prefab - change the variable in there and then do an Instantiate on it? That would mean the value was set before you instantiated the copy.

Given that instantiate just makes a copy of a GameObject - you have the GameObject that is your prefab, you can just change that in the code on the line before the Instantiate and then Instantiate will make a copy using the updated value.

To expand on my previous answer (which I’m doing because this does solve the general problem of setting a variable that needs to be used in Awake or changed before it is called for some reason).

Imagine you have a prefab that contains a reference to another object that is used in Awake:

using UnityEngine;
using System.Collections;

public class DoSomethingInAwake : MonoBehaviour {

     public GameObject otherObject = null;

     void Awake ()
     {
	     print (otherObject.name);
	
     }
}

That is attached to a prefab - let’s say it has null in the otherObject. Clearly this raises an exception when it is instantiated.

The following code could be used to initialise the value of otherObject in advance:

public class InstantiateSomething : MonoBehaviour {

    public Transform prefab;

    // Use this for initialization
    void Start ()
    {
        //add these lines to update the value before instantiation
	    var dsia = prefab.GetComponent<DoSomethingInAwake> ();
        dsia.otherObject = GameObject.Find ("Main Camera");
        //instantiate the updated prefab
  
	    GameObject.Instantiate (prefab);
        //prints "Main Camera"
	
    }
}

In your case you would change the GetComponent to return the path agent and set m_pathManager to your current path manager.