Rebinding keys no rama
How create a rebinding input keys system in blueprints; no using rama's plugin.
asked Sep 04 '15 at 03:44 PM in Using UE4
What is in rama plugin, is not exposed to blueprint by default and you can do that only on C++, rama plugin primarly exposes feature not exposed to blueprint. But look on API refrence:
Set bind function is also command in console which oyu can call from blueprint
answered Sep 04 '15 at 04:05 PM
you can bind keys in blueprints, just make a data table that converts the Key's display name into an integer, and use an array of integers to relate each index to a numbered function.
the CSV spreadsheet text would look like this:
then you can create a blueprint struct with a single integer named ActionID, and use that to import the CSV as a data table.
rebinding a key is just changing the value of an integer in an array of integers. the index is the keyID, the value is the FunctionID.
since custom action events don't show up when you press the AnyKey, you need to add them separately, with a macro similar to my MapKeyToAction, but instead of passing in a Key struct, you can pass in an IntegerID, and skip the datatable part. so in the event graph, you would hook up your custom action mapping events to the macro and pass in a literal int for the KeyID. the integer should be a number that is higher than the highest number on your data table, and each action mapping event should use consecutive IDs, so you don't waste space in the array.
you can use the InputTable RowNames and ListOfActionNames to populate your menus with widgets, passing in the index from the ForEachLoop to set the index of each menu card. when you click on a card, you can use the index to determine what keyID to bind, and what ActionID to bind it to.
the custom action events would be bound similar to the V, B, and N keys in this image:
but the KeyID will be a much higher number so it doesn't conflict with all the keys from the datatable.
To create the setbind console command as above you need to create a class that can run console commands and be saved. Normally you would do this in the gameInstance class since it stays the entire game run-time.
The gameInstance class doesnt allow the ExecuteConsoleCommand node however.
So I suggest creating a blueprint interface with a function in it that called RunConsoleCommand with a stringinput "ConsoleCommand" that simply executes a console command in from that string with the "ExecuteConsoleCommand" node and it has to have a dummy return so just add a boolean output on the function and dont connect anything to it.
NExt in the blueprint interface add "GetSettingsInstance" which simply takes nothing in and outputs "gameSettings" (this will be a save game class you create next)
Then create a savegame class that saves all your key bindings.
Now take a class that the user will interact with and add the BPI and for the RunConsomeCommand under "Interfaces" on the left hand tool bar with the blue f simbol, input a string for setting the bind to whatever key and whatever your binding. You can then set that string with an append node to format it however you want and call it wherever to do those binds and it will be saved in your savegame class.
Then create a macro library that takes in an input executution pin, a string "saveGameFile" "saveUserIndex" int and a blueprintinterface (the one you created above) that loads a saved game file like SettingsSaveFile (in your savegameclass make it so it outputs a .sav file to /saved/savegames/ called something like MyGameSettingsFile) and outputs it to an execution pin and a gameSettings pin (save game class) and connect it to the EventInit() event node on your game instance and then promote the gameSettings output pin to a variable called game settings.
In your macro create one last macro called "GetGameSettings" that does exactly as it sounds, it takes in an input execution pin and an input for GameInstance (which you will always connect with a GetGameInstance node) and it outputs an output execution pin and a gameSettings output (your saved game class) it loads the save-game file or class from your savegameclass and then outputs gameSettings in the line earlier which you can bind to a variable like "savedSettings" in any class you want to load the saved bindings from. Make sure these macros are in amacro library so they can be called from any class.
Lastly make sure your either setting up a widget to call those bindings in the function that uses the RunConsoleCommand blueprint interface or you have them called in the class that has that interface added.
Any classses that you want to bind keys from, as well as your gameinstance will have to have that blueprint interface added.
Its a bit more complicated than that but that should get you started.
Don't forget to accept an answer that best clears your question up or answers it so when the community finds your question in the future via search/google they know exactly what you did to fix it/get it going.
answered Sep 04 '15 at 07:20 PM
Hey. I am late, but i was searching for this myself. I am making a simple Game just trying myself out here and there cause i am totally new to this. My problem was that my GF uses an AZERTY Keyboard. but i figured out a workaround. Tho you might want to save the Booleans somewhere else, Im currently figuring out how to save it to a SaveGame file.
Heres my solution.
Home it helped! :)
Follow this question
Once you sign in you will be able to subscribe for any updates here