-
Notifications
You must be signed in to change notification settings - Fork 325
NEW: Allow selection of InputActionReferences from project-wide actions #1779
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
NEW: Allow selection of InputActionReferences from project-wide actions #1779
Conversation
33c8e54
to
371ae05
Compare
This new picker allows us to search InputActionReferences from the project wide actions asset. Since this is asset is in ProjectSettings, a normal object picker doesn't work.
A dangling action reference means a actin reference that point to a non-existent InputAction. This needs to be checked here in case an input action is removed from the project-wide actions asset. Otherwise the UI will still hold on to a dangling action reference.
eefd9bc
to
1b22b98
Compare
{ | ||
//Get all InputActionReferences are stored at the same asset path as InputActionAsset | ||
return AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(asset)).Where( | ||
o => o is InputActionReference && o.name != "InputManager").Cast<InputActionReference>(); |
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.
Do we need this part?
&& o.name != "InputManager
InputManager data shouldn't be an InputActionReference should it ?
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.
You're right, in theory it shouldn't.
But when removing an input action reference from the asset, it seems to show InputManage in the picker window. This was a just a quick fix. Something to improve, depending on the time we have to understand what's happening in InputManager.asset.
|
||
private static void CreateInputActionReferences(InputActionAsset asset) | ||
{ | ||
var maps = asset.actionMaps; |
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.
Do we need a check here to make sure the asset doesn't already have the InputActionReferences before they are created?
var actionReference = ScriptableObject.CreateInstance();
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.
I guess not as its only called from CreateNewActionAsset
// Check if all actions have a reference | ||
foreach (var action in asset) | ||
{ | ||
var actionReference = existingReferences.FirstOrDefault(r => r.m_ActionId == action.id.ToString()); |
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.
Feels like we could do this faster, e.g. by generating a hash in the above foreach look and then checking if its in the hash here - rather than splining the eixtingReferences list on every action in the asset.
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.
Thanks. We probably can. I'll leave it for the end in case the direction in this PR is accepted.
Are you suggesting to create some kind of dictionary to associate the action ID hash of the reference with the reference itself ? So that we can then use the action.id
here as a key ?
Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs
Show resolved
Hide resolved
...m.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputActionReferencePropertyDrawer.cs
Show resolved
Hide resolved
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.
I believe this could be a valuable change to enable testing of pre2 but I do not think its a solution for InputActionReference (nor is the branch it is based on). I still believe that a way forward could/would be either integrating InputActionReference into UITK editor workflow or use OnValidate() on related assets to fix InputActionReferences. Likely a combination is needed and have a serialised array in the InputActionAsset instead of Load to track them in order to allow that array to follow the same Undo operations and the ScriptableObjects themselves.
I added some questions/comments below relating to the implementation. My main comments for feedback with Request changes are:
- This PR (as the referenced PoC PR) needs unit tests for the added functionality to at least have some test coverage as part of CI.
// Check if referenced input action exists in the asset and remove the reference if it doesn't. | ||
foreach (var actionReference in existingReferences) | ||
{ | ||
var action = asset.FindAction(actionReference.action.id); |
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.
When testing the branch I have a NullReferenceException here in PlayMode after some edits and entering PlayMode (Not sure about exact steps to reproduce, will update his comment if I can reproduce again):
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.Editor.ProjectWideActionsAsset.UpdateInputActionReferences () (at ./Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs:123)
UnityEngine.InputSystem.Editor.InputActionsEditorWindowUtils.SaveAsset (UnityEditor.SerializedObject serializedAsset) (at ./Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindowUtils.cs:21)
UnityEngine.InputSystem.Editor.InputActionsEditorSettingsProvider.OnEditFocusLost (UnityEngine.UIElements.FocusOutEvent event) (at ./Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorSettingsProvider.cs:79)
UnityEngine.InputSystem.Editor.InputActionsEditorSettingsProvider.OnDeactivate () (at ./Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorSettingsProvider.cs:54)
UnityEditor.SettingsWindow.OnDisable () (at /Users/bokken/build/output/unity/unity/Editor/Mono/Settings/SettingsWindow.cs:130)
UnityEditor.ContainerWindow:InternalCloseWindow() (at /Users/bokken/build/output/unity/unity/Editor/Mono/ContainerWindow.cs:360)
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.
Hm, interesting. Good catch! Was this when doing a bunch of Undo/Redo actions? I'll try to replicate it as well.
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.
Not sure, my main test case have been creating, deleting, undo, redo, renaming, select again in picker, repeat.... Haven't found this particular one again though.
Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs
Show resolved
Hide resolved
...m.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputActionReferencePropertyDrawer.cs
Show resolved
Hide resolved
....unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputActionReferenceSearchProviders.cs
Show resolved
Hide resolved
@@ -35,7 +35,7 @@ public override void OnActivate(string searchContext, VisualElement rootElement) | |||
// Note that focused element will be set if we are navigating back to | |||
// an existing instance when switching setting in the left project settings panel since | |||
// this doesn't recreate the editor. | |||
if (m_RootVisualElement.focusController.focusedElement != null) | |||
if (m_RootVisualElement?.focusController?.focusedElement != null) |
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.
I noticed you picked up this diff from the original branch, just wanted to clarify this is a general bug fix relating to a post around potential focus controller bug and isn't really related to the subject of the PR, I think it is fine to add anyway but might require its own FIX line in the CHANGELOG / commit message.
...es/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindowUtils.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Show resolved
Hide resolved
Did some additional testing of this branch but failed to trigger the NullReference exception again. In general it seems that this is more reliable than behavior on the PoC branch being referenced and hence this is likely a better choice for pre2. |
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionAssetIconLoader.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
...es/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindowUtils.cs
Outdated
Show resolved
Hide resolved
Added at least one test now |
Known issues to follow up:
|
5d67ea4
to
5fb9517
Compare
Adding @Pauliusd01 for some testing. Heads up that Undo/Redo doesn't work properly and was already captured as a bug |
Unity_2023-10-31_15-40-21.mp4Are we able to keep these tabs always visible no matter the size of the window? Seems very odd in its current state Also, a question about the tabs - why is NONE option only available in ALL and not in every tab? Is it because the tabs are not really tabs but just pre-made searches and it doesn't find "none" in the filter? :D |
I'll have a look if it's easy, otherwise, I'll poke the Search team about this. I wouldn't consider it a blocker but definitely something to improve. |
Is there a reason why if an action is deleted in Project Wide Actions the reference defaults to NONE instead of Missing (like for custom actions assets)? Could give the user a different impression - unfinished work vs broken work |
Unity_2023-10-31_16-02-44.mp4Are these area tags the same as the existing tabs? If so, why are they returning nothing? |
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.
LGTM. Had non blocking minor things listed in comments (I can report those separately if needed, just let me know) Other than those and the undo redo issues did not notice anything broken, references seem to handle deleting,duplicating, basic renaming just fine for both ProjectWideActions and custom ones
Thanks a lot @Pauliusd01 🥇 I'll have a look at the issues you reported and try to address them today. The ones that are not easily fixed, I'll create a ticket. |
… query OpenInBuilder mode allows to search by "tags". But no implementation was done so they did not work.
I removed this from the search in my last commit. |
|
||
private static string FetchLabel(SearchItem item, SearchContext context) | ||
{ | ||
return FetchLabel((item.data as Object) !); |
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.
This line doesn't compile.
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.
Could you clarify in what circumstances (editor version, OS, etc) ? I haven't seen any compile errors on my side and others, or CI.
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.
Sorry this was my mistake, I was trying to enable global actions on an earlier Unity Editor version that isn't supported.
Description
https://jira.unity3d.com/browse/ISX-1660
https://jira.unity3d.com/browse/ISX-1664
Changes made
This PR allows users to select InputActionReferences from project-wide actions.
It is based on most of the POC work done in #1768 but with some refactoring:
.inputaction
assets. More specifically, project-wide actions don't have InputActionReferences as sub-assets, which means they are not updated once theScriptedImporter.OnImportAsset runs
. This means we need to "manually" update the InputActionReferences to match the existing input actions in the project-wide actions asset. Essentially, making sure that input actions in the asset have references, and also making sure that the references point to the correct input action.Notes
Feel free to capture issues regarding the Undo system so that we can deal with them in a separate PR.
I believe if users can use action references they added, renamed, or deleted in project-wide actions, it is still valuable to pre.2, even if there's some stabilization to be done regarding Undo actions.
Checklist
Before review:
Changed
,Fixed
,Added
sections.([case %number%](https://issuetracker.unity3d.com/issues/...))
.Area_CanDoX
,Area_CanDoX_EvenIfYIsTheCase
,Area_WhenIDoX_AndYHappens_ThisIsTheResult
.During merge:
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.