- Home /
Instantiating in editor not saving prefab connection?
Hello,
I know a few questions have been asked about this but I still need help.
Ok so I am using a JS script to instantiate some objects in the editor, The script has a function that is being called by a C# editor script. So when it calls the function and the objects are created it does not save the prefab connection... I looked at the docs and googles it but I can't find a solution.
thanks!
Bump
Answer by DaveA · Jan 14, 2011 at 12:08 AM
Make sure you're using PrefabUtility.InstantiatePrefab
That does not work in a non editor script... I explained my set up above. I use a editor script to call a function from a non editor script. I am not really good at C# or editor scripts
Perhaps you could post some code for review here. Where is the instantiate done, in the editor script, or the non editor script?
In case someone reaches this question with new Unity versions, this is currently done using PrefabUtility.InstantiatePrefab.
@raimon.massanet: Thanks for the hint. I will fix the answer.
Answer by Robindoo · Jan 05, 2011 at 05:04 AM
You can try creating a script containing the variables for the prefabs. From there, using GetComponent to retrieve the prefabs from your main script.
For example, in Prefabs.js
var prefab1 : GameObject;
Then in your main script,
var getPrefab : Prefabs;
var newPrefab;
function Awake()
{
getPrefab = gameObject.GetComponent("Prefabs");
newPrefab = getPrefab.prefab1;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613094102im_/https://answers.unity.com/themes/thub/images/avi.jpg)