Skip to content
Snippets Groups Projects

Creating Actions and Binding them from C++

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Jan Delember

    This allows binding "keys" to functions indirectly, by introducing a unique action, which calls your method with your parameter(s).

    Edited
    HeaderAndSource.cpp 477 B
    • Author

      Also interesting might be to only add Axis/Actions if they are not defined yet.

      void AddAxisIfNotDefined(UInputSettings* Settings, TArray<FInputAxisKeyMapping> DefinedAxis, FInputAxisKeyMapping NewAxis)
      {
      	for(FInputAxisKeyMapping Action : DefinedAxis)
      	{
      		if(Action.AxisName == NewAxis.AxisName) return; //Dont Add
      	}
      	Settings->AddAxisMapping(NewAxis);
      }
      
      // E.g. in StartupModule
      UInputSettings* Settings = UInputSettings::GetInputSettings();
      const TArray<FInputAxisKeyMapping> DefinedAxis(Settings->AxisMappings);
      AddAxisIfNotDefined(Settings, DefinedAxis, FInputAxisKeyMapping(TEXT("VRSimulatorRight"), EKeys::D, 1));
      AddAxisIfNotDefined(Settings, DefinedAxis, FInputAxisKeyMapping(TEXT("VRSimulatorRight"), EKeys::A, -1));
      

      If the user now changes the bindings, they are not forcefully added back on restart

      Note: The settings are not directly stored into the DefaultInput.ini, but in the Saved/Config/Windows/Input.ini and are copied over if changes are made in the editor UI

      By Sebastian Pape on 2020-04-06T14:46:25 (imported from GitLab)

      Edited by Jan Delember
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment