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"

GetPawn() in AIController always gives me null

Hi everybody! I have a problem with AIController class: when I call GetPawn() function it always give me a null pointer. This is my AMyAIController.cpp:

 void AMyAIController::setDestination(FVector destLocation) {
     targetLocation = destLocation;
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("your click: X=%f, Y=%f, Z=%f"), targetLocation.X, targetLocation.Y, targetLocation.Z));
 
     APawn* pawn = GetPawn();
 
     if (pawn) {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("I've found my Pawn!")));
     }
 }

And this is MainCharacter.cpp:

 AMainCharacter::AMainCharacter() {
     AIControllerClass = AMyAIController::StaticClass();
 }

what am I doing wrong?

Product Version: UE 4.9
Tags:
more ▼

asked Oct 05 '15 at 05:09 PM in C++ Programming

avatar image

AleSpini
33 6 6 8

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

1 answer: sort voted first

Hello AleSpini,

I believe the function that you're looking for is GetControlledPawn which is a function of AController. AAIController inherits from AController so you'll be able to access this function. You can find more functions of these two classes here:

AController: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AController/index.html

AAIController: https://docs.unrealengine.com/latest/INT/API/Runtime/AIModule/AAIController/index.html

Hope this helps!

more ▼

answered Oct 05 '15 at 09:23 PM

avatar image AleSpini Oct 05 '15 at 11:38 PM

Thank you! I tried your solution, but it didn't work as well. Then I checked through the AController functions and I found GetCharacter(). Using that function resolved my problem. Thank you!

avatar image AleSpini Oct 10 '15 at 12:11 PM

Sorry, my last comment isn't true, I changed some things in my code, then I used GetControlledPawn() and all worked! So the right function to call is GetControlledPawn(). Thank you Matthew.

(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