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);
}
