x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to access custom player controller from character class?

Hi,

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.

Thanks, Jack

Product Version: Not Selected
Tags:
more ▼

asked May 17 '19 at 09:39 AM in C++ Programming

avatar image

Jack W Lewis
9 5 5 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

GetController() returns controller that currently possessing the pawn, either AI or player controller:

https://api.unrealengine.com/INT/API/Runtime/Engine/GameFramework/APawn/GetController/index.html

If pawn is not possesed it will return nullptr, so do a check before starting doing calls to player controller

more ▼

answered May 17 '19 at 10:09 AM

avatar image

Shadowriver
36.6k 932 169 1111

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

alt text

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.

alt text

The following code uses that reference to do some fancy headbobs. Camera transitions should work similarly. Commented out because, well, headbobs.

alt text

WW_Player here, is a first person C++ only class, derives from character class and automatically generated by a custom GameModeBase.

zzref.png (37.3 kB)
zziinits.png (64.9 kB)
zzheadbobs.png (37.2 kB)
more ▼

answered May 18 '19 at 06:07 AM

avatar image

DebashishPatra
24 3 4

avatar image Jack W Lewis May 18 '19 at 11:55 AM

This seems to get my player controller but not my custom player control. I need to run a function from my custom one from the character class input component.

avatar image mightyenigma May 20 '19 at 06:21 PM

Is the game starting up using a GameMode that assigns your custom Player Controller by default? If not, are you explicitly telling to create and assign your custom controller to each player?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question