-
Notifications
You must be signed in to change notification settings - Fork 329
FIX: Project wide actions enabling actions overrides PlayerInput (ISXB-920) #2144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
0c77ea4
f6480e7
d9e3b6a
6afc84a
2029be3
98dec35
4f64381
ae27089
1655b7f
b05b5e8
acf6225
9c6cda3
67002de
0e4b64b
8fab5a9
55b7d71
ce0a9a5
805f0d9
93a4c69
53a0e98
9654ffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,8 +342,14 @@ public InputActionAsset actions | |
| UninitializeActions(); | ||
| } | ||
|
|
||
| var didChange = m_Actions != null; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is related to your question around comparing InputActionAssets? It's not going to be cheap to compare, but a comparator would be useful. Additionally that comparator could compute a hash to make the comparison cheaper. However, this could also be fine since it will very likely be different if it's another instance. Otherwise the project itself is oddly designed.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, all this is around avoiding copying the asset multiple times, which works as far as I tested and for the cases I could come up with, but like you said ideally it would be great to be able to compare an copy of asset to it's original to determine that it's a clone of the asset. |
||
|
|
||
| m_Actions = value; | ||
|
|
||
| if (didChange || m_Enabled) | ||
| // copy action asset for the first player so that the original asset stays untouched | ||
| CopyActionAssetAndApplyBindingOverrides(); | ||
|
|
||
| if (m_Enabled) | ||
| { | ||
| ClearCaches(); | ||
|
|
@@ -1373,14 +1379,7 @@ private void InitializeActions() | |
| for (var i = 0; i < s_AllActivePlayersCount; ++i) | ||
| if (s_AllActivePlayers[i].m_Actions == m_Actions && s_AllActivePlayers[i] != this) | ||
| { | ||
| var oldActions = m_Actions; | ||
| m_Actions = Instantiate(m_Actions); | ||
| for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++) | ||
| { | ||
| for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++) | ||
| m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]); | ||
| } | ||
|
|
||
| CopyActionAssetAndApplyBindingOverrides(); | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -1430,6 +1429,18 @@ private void InitializeActions() | |
| m_ActionsInitialized = true; | ||
| } | ||
|
|
||
| private void CopyActionAssetAndApplyBindingOverrides() | ||
| { | ||
| // duplicate action asset to not operate on the original (as it might be used outside - eg project wide action asset or UIInputModule) | ||
| var oldActions = m_Actions; | ||
| m_Actions = Instantiate(m_Actions); | ||
| for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++) | ||
| { | ||
| for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++) | ||
| m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]); | ||
| } | ||
| } | ||
|
|
||
| private void UninitializeActions() | ||
| { | ||
| if (!m_ActionsInitialized) | ||
|
|
@@ -1799,6 +1810,13 @@ void Reset() | |
|
|
||
| #endif | ||
|
|
||
| private void Awake() | ||
| { | ||
| // If an action asset is assigned copy it to avoid modifying the original asset. | ||
| if (m_Actions != null) | ||
| CopyActionAssetAndApplyBindingOverrides(); | ||
| } | ||
|
|
||
| private void OnEnable() | ||
| { | ||
| m_Enabled = true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe insert a new line after this one and add a comment why there is a split now?