I'm using UnitySteer, and its SteerForTarget component destroys itself if its target value is not set on Awake. I can't figure out how to spawn a vehicle that has that component without it destroying itself.
I don't know the answer to this, but I was just dealing with a similar problem. I wanted a prefab to reference something in the Scene as its Target. What I ended up doing was creating a near public String TargetTag, and modified SteerForTarget behavior to this:
public string TargetTag;
void Awake()
{
if (TargetTag != null)
{
GameObject gob = GameObject.FindWithTag(TargetTag);
Target = gob.transform;
}
if (Target == null)
{
this.enabled = false;
}
}
I have not fully tested this yet, but one option is to set the SteerForTarget script's "target" property to it's own transform.
Since you can't set the target property of a prefab, first instantiate the prefab manually by dragging it into the game view. Then set the newly instantiated SteerForTarget.Target property to the GameObjects own transform. Now update the prefab by dragging the GameObject from the Hierarchy back into the Project view.
Now you should be able to set a new Target in your code.
I know it's a bit of a hack, but it works okay for me so far.