How to access custom player controller from character class?
How would I access my my custom player controller from my character class? In some peoples code I've seen people use something like this CPC->GetControlRotation(); for example. Where I assume CPC is the stored name for their CustomPlayerController. But without the rest of their code I can't see how they actually access the controller.
asked May 17 '19 at 09:39 AM in C++ Programming
Jack W Lewis
GetController() returns controller that currently possessing the pawn, either AI or player controller:
If pawn is not possesed it will return nullptr, so do a check before starting doing calls to player controller
Here is some code to get you started.
You can simply declare variables in header if you do not want to repeatedly refer the variables.
You can initialize the variable like this. As @shadowriver mentioned, if your character is not posessed by an AI /Player, it will return null. As for the following code, the first posessed pawn/character is saved. Following does this in BeginPlay.
The following code uses that reference to do some fancy headbobs. Camera transitions should work similarly. Commented out because, well, headbobs.
WW_Player here, is a first person C++ only class, derives from character class and automatically generated by a custom GameModeBase.
answered May 18 '19 at 06:07 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here