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"

My cast<> too APlayerController is failing. Need help.

Hey, i'm trying to get access to my HUD from my FPS character. Currently i'm trying this out

     APlayerController* MyPC = Cast<APlayerController>(Controller);
     if (MyPC)
         MyHUD = Cast<AProject_RewindHUD>(MyPC->GetHUD());
         if (GEngine)
             GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "Error!");

But this does not work for me as i'm always getting the error. From what i read this should work. Anyone have any idea why it is not working for me? I currently have no self made player controller class, is one required to get the HUD?

Product Version: Not Selected
more ▼

asked Feb 17 '15 at 02:09 PM in C++ Programming

avatar image

200 54 54 64

avatar image jechli Mar 17 '15 at 10:54 PM

Bumping this up a bit, I'm having the same issue, but with casting AAIController to AController:

pawnController = Cast(OwnerComp.GetAIOwner());

This is giving me this error message:

Error 2 error C2664: 'AController TCastImpl ::DoCast(UObject )' : cannot convert argument 1 from 'AAIController ' to 'UObject ' C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\CoreUObject\Public\Templates\Casts.h 135 1 LostEchoes

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

2 answers: sort voted first

Have you declared the MyHUD variable? E.g. have you tried the following: AHUD* MyHUD = Cast(MyPC->GetHUD());

You could also check if your PC or HUD is valid:

GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, MyPC->GetName()); GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, MyHUD->GetName());

What is your error message?

more ▼

answered Mar 18 '15 at 11:13 AM

avatar image

431 38 48 143

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


when do you call that method? Can you please check if the Controller isn't NULL at that point before, so we know it's a matter of the cast. (as it might as well just be NULL already before and you try to cast -> NULL again) Maybe you need to call the method after the pawn is possessed by a controller ( I guess you call it really early, like in the constructor?)

Thanks :)

more ▼

answered Mar 18 '15 at 11:28 AM

avatar image

316 37 39 44

(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