Prefab and creating objects in script help

Okay I have a few questions about prefabs and creating duplicates in script.

  1. I’ve made a prefab in the project tab, but does there have to be one instance of the prefab in the hierarchy?
  2. How do I actually find the prefab in script? All the unity manual examples show duplication of the object that the script is in, but I want to duplicate on object that does not have the script in.
  3. I’m supposing you set the prefab to a variable and then use Instantiate(avariable,Vector3,Quaternion.identity); Please correct me if I’m wrong.
  4. My object has an animation that is set to play automatically. Will duplicating it reset the animation or will it also duplicate the time in the animation that it is at? In this case I’m just supposing that I’ll have to change it to activate using script but I’d rather know ahead of time.
    Thanks for any answers, sorry if this is all too much for a single question, but I feel pretty straight forward about what I need to know at this point. Sorry if I’m missing any important information, I’m still new to scripting.
  1. No.

  2. You can load a prefab at runtime using Resources.Load or you can create a public field in your script, e.g.

    public Transform SomePrefab;

and using it in Instantiate method. To assign some prefab to it, click a script in project explorer, it will show in Inspector windows and you will notice “Some Prefab” on top of it. Drag any prefab from project explorer to it and that’s all.

  1. Yes, though you can use other overloads as well.

  2. This I don’t know, but should be very easy to check.

Complete description of steps required to instantiate prefab is available here: Instantiating prefabs.