Spawning game objects in edit mode vanish after switching scenes
Hello,
So I've trying to spawn game objects while in edit mode, which I have worked just fine however soon as I switch scene (never enter play mode) and then switch back, all the objects I just created vanish.
I have [ExecuteInEditMode] at the top, here is my spawning code:
private void AddWaveSystem()
{
if (GameObject.FindObjectOfType<WaveManager>())
{
Debug.Log("WaveManager Already Exists!");
return;
}
GameObject go = new GameObject("WaveManager");
go.AddComponent<WaveManager>();
}
This spawns the object just fine, but it's not saving. Any help is great, Thanks!
He is doing it in edit mode, not playmode
Yeh, I'm trying to do all this without playmode, I'm changing scene via my assets folder and never entering playmode.
Either you forgot to save scene when switching or the new GameObject was not serialized to scene when instantiate which I know it happen when call new GameObject()
(from older version of unity) ins$$anonymous$$d of Object.Instantiate
.
So you can try call Object.Instantiate
. If it not save inside your scene, then press Ctrl+S a few times
Answer by Alex_lemes · Sep 18, 2018 at 12:23 PM
after some research into editor tools, I managed to fix the issue by using ObjectFactory, thanks for the help. code:
private void AddWaveSystem()
{
if (GameObject.FindObjectOfType<WaveManager>())
{
Debug.Log("WaveManager Already Exists!");
return;
}
ObjectFactory.CreateGameObject("WaveManager", typeof(WaveManager));
}
Your answer
Follow this Question
Related Questions
Why can't you add editor scripts to GameObjects even if the tag is EditorOnly? 0 Answers
Editorscript: How to reference prefabs in editor not in awake or start 0 Answers
Destroying object multiple times. 0 Answers
selecting prefab from project window with Editor script 1 Answer
Scripted GameObjects vs Prefabs 0 Answers