- Home /
How to set a default prefab on a C# script?
I am wanting to set a default prefab value on a script in the inspector, using the fields that are exposed when you click on the actual script, however, these references seem to be reset whenever I actually instantiate one of these objects. Is that not what the field is for in the inspector? If not, what does it do?
Thank you.
Answer by kromenak · Jan 04, 2014 at 03:35 AM
Unfortunately, those default fields only work in the editor. For example, if you set a default value on a script and then attach that script to a GameObject in the editor, that default value should be applied as expected. If you instantiate a script at runtime (using AddComponent), this doesn't work. Agreed it would be awesome if it did, but I think that sort of metadata associated with the scripts is not accessible at runtime.