void Start () function works differently with ExecuteInEditMode?

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?

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

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

That's it! Start() get's called again when the game stops! To get around the problem, I can only create game object when (Application.isPlaying)

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.

It would be nice if that were the case, but the game objects created by my script do not have any scripts with the [ExecuteInEditMode] attribute. It seems that the Start() function on [ExecuteInEditMode] scripts runs before the game is considered to be in Play mode. Game Objects that are by functions in my [ExecuteInEditMode] script AFTER the Start() function runs DO delete themselves normally once the game leaves play mode.

If you have both rotations around y, such as Ry1 and Ry2, then Ry1*Ry2 is just adding the y-rotations. It's a super-easy special case. In math. that's called a degenerate case. If only 1 is around y, it's as complex as all the rest.