I am using a script with the ExecuteInEditMode attribute.
This script creates a few GameObjects in the Start function. These GameObjects are are created when I press the play button to start my game.
Then when I press the play button again to STOP the game, the GameObjects created by the script exist in the hierarchy. Additional game objects are created every time I play the game.
In contrast, when GameObjects are created in the start function of a script that does not have the "ExecuteInEditMode" attribute, the GameObjects are deleted from the hierarchy when the game stops.
Why is this? Is there a clean way to have an ExitInEditMode script add GameObjects during runtime without making permanent changes to the scene file?
2 Answers
2
You should be carefully to what scripts you add that attribute. Start() is called everytime the game "starts". But with ExecuteInEditmode when you leave the `playmode` everything is destroyed normally but you just entered editmode! That's why Start() is called again. (At least that's what i guess, haven't tested it). What's the reason why you want your script to run inside the editor?
Anyways, you have to check whether your game is running or not.
if (Application.isPlaying)
For more details take a look at the scripting reference
I am not sure as I've never played with the Executeineditmode, but looking at the doc, it says that whatever script with this attached will always be running, including in editmode.
So i'm assuming whatever objects you create, you probably have a script attached to them that has "executeineditmode" as well.
taking the mode off of those script should fix the problem. but again I could be wrong.
Quite degenerative when in your answer you also have Ry. which maybe mean rotation around y,x? Right?. Order of what? A * B not equal to B*A where A,B are Quats Good answer can be found here. https://gamedev.stackexchange.com/questions/140579/euler-right-handed-to-quaternion-left-handed-conversion-in-unity
– winxalex