EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
이것을 호출 하면 instantiate 한 GameObject 가 에디터를 껐다 킨 이후에도 정상적으로 저장되어 있음
하단은 저장 관련한 내용들..
I am using Unity 2019.2.6f1
I have a single scene that I am using for the main field of play. All characters are prefabs. Each level is saved to a JSON file that controls which characters are to be loaded for the scene and where they are to be positioned.
I have an editor script (SaveLevel) that will create the JSON file based on how I have the scene configured in the editor. I have a second editor script (LoadLevel) that will read the JSON file and set up the scene for that level.
This is all done in the editor at design time. I can save and load levels fine. However, after I load a level, if I hit the play button, to test the level, the scene resets to an empty scene (how it was before I loaded the level).
How can I load my prefabs into my scene and save the scene so that I can test the level?
Here is my code for loading the level:
-- EDIT -- Based on the response by @Ron the fix is the code change in LoadLevel() below.
...
Are you saying that you run this code inside the editor, see the gameobjects created in the hierarchy and scene view, and when you hit play it resets to an empty scene? – Ron Nov 10 '19 at 20:48
- Yes, except the scene's not completely empty. All of the gameobjects that are saved with the scene, before I run my script, are still there. Only the gameobjects added by my script are missing. – Don Shrout Nov 10 '19 at 22:22
- C# != UnityScript (which is a Javascript derivative created for unity). – Llama Nov 11 '19 at 0:51
- @John thanks for the clarification. I added the UnityScript tag because this is a question about code not just the editor. I didn't realize that UnityScript was the official title for Unity's version of JavaScript. I've only ever used C# with Unity. – Don Shrout Nov 11 '19 at 12:50
- Can you try calling EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); before you call EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo(); – Ron Nov 13
stackoverflow.com/questions/58790108/load-prefabs-via-script-and-save-scene-in-unity-editor
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
ScriptableObject 사용 예시 (0) | 2021.11.03 |
---|---|
머신러닝 강화학습 (ML-Agents) (0) | 2021.07.04 |
부모 자식간의 콜리전 분리 (0) | 2021.04.20 |
Vector3.Scale : Multiplies two vectors component-wise. (0) | 2021.01.13 |
Prefab Control, UnpackPrefab completely (0) | 2020.12.20 |