Adding Script to an "Instantiated" Prefab?

Ok I am sure I am forgetting to do something dumb, but I have a folder full of prefabs that gets created. When I Instantiate them, I want to add a script to them.

for example:

Instantiate(myPrefab, position , rotation);

This loads the object, but it does not add my script. It gives me an error that says:

Can’t add component ‘MonoBehaviour’ to myPrefab because the game object is a generated prefab and can only be modified through an AssetPostprocessor.

Is there any way to add these scripts to prefabs on the fly without using AssetPostprocessor?

Thanks in advance

GameObject go = Instantiate(myPrefab, position, rotation) as GameObject;

That shoult do the trick. Instantiate returns the new instance of your prefab in your scene. myPrefab is the prefab itself → an editor thing.

Hope it helps :slight_smile: