Unity-Technologies / InputSystem

An efficient and versatile input system for Unity.
Other
1.42k stars 306 forks source link

FIX: InputActionReference when using FEPM (ISX-1968) #1949

Closed timkeo closed 2 months ago

timkeo commented 2 months ago

Description

When Domain Reloads are disabled, InputActionReference instances continue to reference the "old" InputAction object from the previous PlayMode session. This fix clears the InputAction reference when exiting PlayMode allowing it to be reloaded in the next session.

Although Configurable PlayMode options, aka Fast Enter PlayMode, isn't currently supported, a number of tickets have been filed against this issue including:

indicating FEPM is quite a popular feature and fixing this issue is beneficial to our customers.

Furthermore, the underlying problem is a bug in its own right regardless of FEPM: the underlying Action instance is invalid for EditMode and holding the reference is dangerous as it keeps the object "alive" along with the pointers to native memory buffers that are de-allocated when exiting PlayMode. In short, attempting to access the ActionReference after leaving PlayMode can cause an AV and crash the Editor.

Changes made

When exiting PlayMode, all InputActionReference instances are queried and their m_Action field is reset. This forces a "reload" of the Action from the Asset the next time its accessed just as if a Domain Reload had occured.

Notes

This issue is completely separate from my CoreCLR refactor and can be fixed independently of it.

Checklist

Before review:

During merge:

After merge:

timkeo commented 2 months ago

The tvOS failure is a per-existing issue and unrelated to the PR, which is an Editor fix that doesn't affect Players.