Why Casting of my ThirdPersonCharacter is failed?

Hello, I try to cast my ThirdPersonCharacter but for some reason it is always failed. Why can it be so? Bluprint is attached.

Thank you in advance.

Alex

If this doesn’t work then please show where you are spawning the character

If you are using the default unreal settings then make sure in the Game Mode that you have “Default Pawn Class” set to BP_ThirdPersonCharacter

If you are spawning it manually in GameMode PostLogin event then make sure the spawned and possessed pawn is of type BP_ThirdPersonCharacter

P.S
The controller is not the character. The controller can unpossess and possess characters and control them. Hence it cannot be cast directly to the character.

The only thing is here is, the begin play spawnes in your world before the character controller, even in miliseconds before. In order to solve this, you can put delay in your begin play or can have a tick until controller validated and never execute it again. Many ways to do that.

3D Raven, thank you for your reply. Unfortunately it is still Failed. Could you let me know where I can find the “Default Pawn Class” setting? I visited the Project Settings, and there is no “Default Pawn Class” there. I am sorry for my stupidness. I am still a total begginer in UE5.

Hello CtnDev, I am not sure if I’ve done it correctly, I’ve placed a Delay function between EventBeginPlay and Cast To BP_ThirdPersonCharacter. Duration of the delay is 0.1. It still doesn’t work. Here how it looks now:

Thanks.

Go to your project settings and follow instructions.

Here is the working cast in my sample project

Using get player character directly also is successful.

Perhaps do a IsValid test of “last hit by” before casting. I’m guessing the character has not been hit at the start of the game

(not sure why you are even testing “last hit by” at the start, is that a mistaken click, should it not be a direct cast of the player character?)

Thank you very much for your assistance 3D Raven. Unfortunately it still doesn’t work.
Here how it looks, for some reason, my UE5 added a Target node between Get Player Controller and Get Controlled Pawn. It adds it automaticaly. Anyway, still doesn’t work.
And yes, I opened the preferences and it was set there correctly. :frowning:
You also asked me “Show where you are spawning the character, If you are using the default unreal settings or If you are spawning it manually”

Well maybe here is the reason. First of all I don’t know how I spawn it, manually or by default. I use the default third person map and I just removed all objects from there and created there my own scene. This is how I did it. I believe it spawns the charecter “By default” there, but I am not sure.

Another important thing is that I clicked something(don’t know what), and now when I start the game, when I click on the play button, it starts the game firstly without the character (I only fly) and only after I click on the “controller button” - it spawns the character and I start to really play. Maybe this is the reason?

Thank you. The screenshot is attached.

Yeah, that was the reason :slight_smile: I’ve found how to make is spawning from the first time.
To all people who had the same problem, you should switch to this option here:

Try pressing the three dots at the end of the play icon’s bar. See what mode the game is starting in. Try switching to “selected viewport” or pie or “standalone game”
The character should spawn in these modes. Perhaps you are on “Simulate”?

1 Like

Yeah, thank you very much 3D Raven. You very helped. It was the problem and thank to your assistance we’ve got the gist of it. Many thanks!

I’m having this problem but none of the suggestions here changed a thing.

ok so, my thirdperson BP = MasterCharacter BP just a name change as far as I know. I’m a beginner to Unreal 5.3 but not completely computer illiterate. It’s starting to seem like all my problems might be related. I cannot get my root motion jump to work (screenshot 1)

I first noticed it was failing to cast to MasterCharacter (thirdpersonBP) in some health potion logic (screenshot 2)

screenshot 3 is in game showing the print string ‘fail’ for the health potion

screenshot 4 is another example I believe where it’s failing to cast to MasterCharacter (thirdpersonBP) I get errors saying the hud is not set or invalid or something and the hud just doesn’t work also.

Please if there are any pros out there willing to help a noob, please, please, please! I’ve been trying to work around this for months now hoping that it would work itself out or I would realize some silly mistake that I made but the casting and getting owner/character/pawns/controllers/etc is beyond me still.

attach your print strings to the object your casting to, rather than just getting ‘failed’ it’ll tell you what you passed in which will help debug it, or if it prints nothing it means it was null.

you last pic tells you the problem, you want to pass in a controller not the pawn