[BUG] FSM not compatible with disabled domain reload
See original GitHub issueDescribe the bug Variables use OnEnable to reset themselves
However, Unity does not call OnEnable on scriptable objects when entering playmode IFF:
- the ScriptableObject is already loaded
- domain reload on play is disabled
To Reproduce Steps to reproduce the behavior:
- Disable Domain Reload
- Create any variable
- Change the variable value during play mode
- Value will be preserved on next play mode
Expected behavior Variables should reset to initial value for every play mode sessions
Additional context My current hack
using UnityAtoms;
using UnityEditor;
using UnityEngine;
namespace Atoms.Editor.EnsureVarReset
{
// ensure class initializer is called whenever scripts recompile
[InitializeOnLoad]
public static class EnsureVarReset
{
// register an event handler when the class is initialized
static EnsureVarReset()
{
// Whenever the game enters or leaves playmode
EditorApplication.playModeStateChanged += LogPlayModeState;
}
static void LogPlayModeState(PlayModeStateChange state)
{
// Reset each loaded variable
foreach (AtomBaseVariable variable in ScriptableObject.FindObjectsOfType<AtomBaseVariable>())
{
// Reset the var
variable.Reset();
}
}
}
}
Issue Analytics
- State:
- Created 4 months ago
- Comments:11
Top Results From Across the Web
Bug - Addressables.LoadSceneAsync Breaks with Domain ...
When I try to load a scene via the addressables system it loads correctly the first time, but when I run play mode...
Read more >Support disabling domain reloading · Issue #1518
Unity 2019.3 has an experimental feature that disables domain reloading when entering play mode. This skips (re)initialising game state, ...
Read more >Instantly Enter PlayMode Unity 2019.3 for ...
But it seems playmaker is not correctly working yet when I disable Domain reload? Every Fsm stays on first state.(I can forced to...
Read more >Manual: Domain Reloading
Disabling Domain Reloading To disable Domain Reloading: Go to Edit > Project Settings > Editor. Make sure Enter Play Mode Options is enabled....
Read more >Using Reflection To Help Disable Domain Reload
When domain reload is disabled, the method ResetStatic() will be invoked by Unity before running the game. You would want your static variables ......
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 Free
Top 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
if you wanna elaborate on that topic or bring up implementation ideas that could solve that without harming performance or other implementations, feel free to do so, But I’d ask you, to do so in #323 (feel free to re-open the ticket if necessary!)
what is considered “incorrect state”? that’s business logic, only you can decide about that and you could write an validator for that.
modifying the FSM implementation to throw errors in that case, would force you to setup every possible transition.
let’s say you feed your keyboard input as actions into your FSM to handle your game state WORLD —ESC—> MENU WORLD — I —> INVENTORY …
that way you only handle transitions and every key that is not a transition is a “stay in state”. works perfectly fine, but does not work anymore (or would spam warnings) if #323 would be implemented.
the issue in this case is less that the FSM does not throw warnings, the issue is more that the FSM was able to be in an invalid starting state that was seemingly not visible in the inspector (as you had to resolve to the debug inspector)