[Feature] Making UnityAtoms compatible with Enter The PlayMode feature of Unity
See original GitHub issueEnter The PlayMode is a feature that makes entering the play mode insanely fast.
But there are side effects:
- Fields marked with [NonSerialized] attribute keep their values - as script serialization step is skipped completely and scripts remain the same, all data is carried to the Play Mode.
- Static variables keep their values - because Domain Reload does not happen types stay initialized.
- Static events keep their subscribers.
- There is no extra OnDisable/OnEnable calls for ExecuteInEditMode scripts.
- ScriptableObject, MonoBehaviour fields which are not serialized into the build ([NonSerialized], private or internal) keep their values - as existing objects are not recreated and constructors are not called.
- Watch out for null private and internal fields of array/List type - they are converted to an empty array/List object during Domain Reload and stay non null for game scripts.
- ExecuteInEditMode/ExecuteAlways scripts are not destroyed/awaken - no OnDestroy/Awake calls for those.
- Watch out for Awake/OnEnable methods which check EditorApplication.isPlaying property - Awake is not called and OnEnable is called only when EditorApplication.isPlaying is already true on Play Mode change.
UnityAtoms gets heavily impacted by these side effects. OnEnable and OnDisable calls are not called anymore. So nothing works as expected.
I exactly don’t know how we are supposed to change the code at the moment. So I created this issue for the discussion about it.
There are some useful callbacks that we can use.
EditorApplication.playModeStateChanged
event[RuntimeInitializeOnLoadMethod]
attribute
What do you think?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:17 (4 by maintainers)
Top Results From Across the Web
Manual: Configurable Enter Play Mode
To configure the Enter Play Mode settings, go to Edit > Project Settings > Editor and enable Enter Play Mode Options. When you...
Read more >[FEATURE] Use custom SearchWindow to create new atoms
By default Unity Atoms adds many new asset "categories" (Events, Variables, Constants, Actions, etc.) with even more asset types (bool, int, ...
Read more >Configurable Enter Play Mode
Play Mode is one of the key concepts in game development with Unity. The ability to iterate fast in the Editor is a...
Read more >Unity Atoms — Tiny modular pieces utilizing the power of ...
I've been working with Unity for several years, creating mobile games for iOS and Android as well as using it during several Ludum...
Read more >Conditions · Unity Atoms
Now Unfiltered will simply respond to any value passed when SomeIntChanged is raised. Enter play mode and test it by clicking on "Raise"...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks a bunch both of you for the explanations 🙏
I agree, makes sense what you @rhys-vdw are suggesting.
Just to go into more detail on the
RuntimeInitializeOnLoadMethodAttribute
idea:I think you could have a single static handler that calls
Resources.FindObjectsOfTypeAll
like:Might be more appropriate to use
EditorApplication.playModeStateChanged
(as @pnarimani suggested) since exiting playmode is also important.