Editor Script: Linking GameObjects to public script variables resets when playing.

Hey everyone,
I have an editor script that is creating a bunch of gameobjects in a scene. Then it is linking those gameobjects to public variables on a script. It’s working, but when I press play, or change the scene, all of those links in the script go back to None (Game Object). I have manually clicked “save”, as well as done savescene through code. Any idea why this is happening? I have tried both GameObject.Instantiate and PrefabUtility.InstantiatePrefab.


Vector2 defaultLoc = new Vector2(-1000f, 1000f);
        LevelController levContScript = GameObject.FindGameObjectWithTag("LevelController").GetComponent<LevelController>();

        string prefabBasePath = "Assets/Prefabs/";
        string parryImpact = "Modified/ParryImpact.prefab";

        string prefabPath = prefabBasePath + parryImpact;
        GameObject prefabObject = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

        GameObject instantiatedPrefab = GameObject.Instantiate(prefabObject, defaultLoc, Quaternion.identity);
        levContScript.parryImpact1 = instantiatedPrefab;
        instantiatedPrefab = PrefabUtility.InstantiatePrefab(prefabObject) as GameObject;
        levContScript.parryImpact2 = instantiatedPrefab;

What I think the problem is is that you have a variable wich is an Instantiate function and you are trying to put the Instantiate in a Gameobject variable.

What I would do to try and make this code work is just this

Instantiate(your variables).name = addToVariable
levContScript.parryImpact1 = Gameobject.Find("addTovariable")
Gameobject.Find("addToVariable").name = the orginal name

so just create the item and rename it (I would rename it so you could find it easily) then add the object and then rename it again to his orginal name