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.
Thanks…
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;