Getting Input Key Time Down in C++
I hope you guys can help me with this. First of all sorry for my english, I'll try to explain as good as possible.
I have a MyDoor class in my project whose father is an UsableItem class. I want my player (own coded player which have no controller), whose father is ACharacter to close the door if he holds down the "use button" more than 1.5 seconds. The problem is, I cannot access to the Get Input Key Time Down function because the target is a Player Controller and I don't have one of those hehe (or that's what I think).
I've tried some solutions but none of them worked such as: -Casting the ACharacter to MyPlayer in order to get the controller -Adding the generic controller class to MyDoor to get the function -I want to try to create my own timer, but I don't know how to get the key I press because I'm overriding the OnUsed function from UsableItem.
Hierarchy: ACharacter --> MyPlayer UsableItem --> MyDoor
Could you help me out, please? If you want, I can post screenshots of my code, but I don't think it's necessary.
Thank so much in advance.
asked Mar 01 '17 at 10:16 AM in C++ Programming
try the function GetPlayerController: As world context object you can use anything that implements GetWorld(), for instance ACharacter::GetWorld(), and as index use 0. Note that this function returns NULL during actor construction so if you are calling it in a tick make sure to check for NULL. You did not specify whether this is a multiplayer game or not. If it is, be advised that obtaining the player controller like this will only work on clients and non-dedicated servers. If the code you are writing might potentially run on both client and server, call IsLocalPlayer() on the player controller.
With that answered, I'd just like to note that every player-controlled pawn always has a player controller. For me it does not really come through as to what is the player controlled pawn; however, on whichever pawn that is you can just call GetController() on the pawn and cast it to a player controller safely. Casting your pawn to a player controller as you suggested won't work because the classes are unrelated.
As addition to the accepted answer by Univise, that's how you access it:
documentation of the method.: http://api.unrealengine.com/INT/API/Runtime/Engine/GameFramework/UPlayerInput/GetKeysForAction/index.html
answered Mar 20 '18 at 12:43 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here