I want to create a function that when the players enter inside a collision box, over the actor, appear “Press [Action Key] to [Action Name]”, for now it works, but i would like to recieve some tips on how to create a better solution that this. I don’t think it’s the best solution possible, but it works
When the player is inside the collision box i would like that, when he press the action key, he fires a function of that actor.
I don’t know how to solve the second problem, for now i have used blueprint to see when the players click the letter F, but i would like to use c++ only and not checking for when the “F” key is pressed, but when the [Action Key] is pressed.
I am not sure how you want to improve the way you get your string, but if it is a generic message along the lines of “Press X to interact” you could store it in an FString once in BeginPlay.
To assign a function to an action mapping you need to assign it using the BindAction function using the UInputComponent of your pawn. It is easiest to do this in the SetupPlayerInputComponent function. You can read more about it here: UInputComponent::BindAction | Unreal Engine Documentation
Yes, the BindAction function essentially tells the engine to fire a function when a key is pressed. This is because when you use the blueprint node the engine knows what pawn is calling the Action Map and you are writing the logic for what will happen depending on the input. In C++ you have to tell the pawn which function to call when an action map is called using whatever input.
First you need your action map set up in your Project Settings(ProjectSetting->Input). Then you need to use BindFunction. The first argument is the Action Map name, the second is how to read the input (click, double click, release, etc.), the third is what object to call when the key is pressed, and the fourth is what function to call.
Should i Bind an Action even if i’ve already created the action inside the Engine setting?
Isn’t there a way just to check when that action fires like on blueprint when you just input the action name and the blueprint node fires?