Cannot set InputActionReference on a prefab through editor scripting

Hello world, I’m trying to link up Input Actions from the Input System to component fields inside the prefab itself, not an instance of it. But it keeps saying “None” after running the editor script I wrote. It is possible to link it up by hand inside the prefab, but not by editor scripting?

Note: It is possible to link the reference to an instance of the prefab in a scene.

The project comes from the Tanks demo of the Input System package.

[MenuItem("Test/Link Action")]
    public static void LinkAction()
    {
        var contentsRoot = PrefabUtility.LoadPrefabContents(assetPath);

        // Modify Prefab contents.
        contentsRoot.AddComponent<BoxCollider>(); // works

        InputActionAsset asset = AssetDatabase.LoadAssetAtPath<InputActionAsset>("Assets/TanksInputActions.inputactions");
        Debug.Log(asset);

        var action = asset.FindAction("Test"); // I created this on top of the demo
        contentsRoot.GetComponent<TestAction>().ActionReference =
            InputActionReference.Create(action)
        ;

        // Save contents back to Prefab Asset and unload contents.
        PrefabUtility.SaveAsPrefabAsset(contentsRoot, assetPath);
        PrefabUtility.UnloadPrefabContents(contentsRoot);
    }

Same problem, did you find any solution? I’ve also tried this:

var map = _asset.FindActionMap(mapName);
var action = map.FindAction(actionName);
var iar = InputActionReference.Create(action);
iar.Set(_asset, mapName, actionName);

Both map and action are found, but in the editor it ends up as “(Input Action Reference)” and not the actual action.

No, I filed the bug to Unity. It is now on their tracker list.

1 Like