# Can't figure out why these casts are failing all of the sudden

**URL:** <https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124>\
**Category:** Programming & Scripting\
**Tags:** casting, unreal-engine\
**Created:** [October 21, 2024, 7:17pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124 "2024-10-21T19:17:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_AKIMBO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mr\_AKIMBO](https://forums.unrealengine.com/u/Mr_AKIMBO)\
**Post date:** [October 21, 2024, 7:17pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/1 "2024-10-21T19:17:13Z")

</div>

While making a few changes a couple of cast to AI\_controller stopped working out of nowhere:

 ![imagen_2024-10-21_211408102](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/8/a/a8aa669d12cbdd7b87027ac12db46e6a5f8563cd.png)

And in this one not only is the cast failing but the try get pawn owner is being read as not valid, even though when I print it it seems fine:

 ![imagen_2024-10-21_211430864](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/e/b/feb522e8bbaf4bf2f62bea199a0a06fd2ae4bac8.png)

Weirdest thing is that a completely unrelated animation blueprint with comepletely different variables also started having this issue.

---

<div class="post-metadata">

**Author:** ![Glyphrr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/glyphrr/32/988812_2.png) [@Glyphrr](https://forums.unrealengine.com/u/Glyphrr)\
**Post date:** [October 21, 2024, 8:22pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/2 "2024-10-21T20:22:32Z")

</div>

Hey!

What changes were you making? It might give some idea to what went wrong.

In the meantime you can check if you do have the right anim bp selected in your actor and that the character variable is being set from you actor bp to your anim bp.

---

<div class="post-metadata">

**Author:** ![Mr\_AKIMBO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mr\_AKIMBO](https://forums.unrealengine.com/u/Mr_AKIMBO)\
**Post date:** [October 21, 2024, 8:46pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/3 "2024-10-21T20:46:15Z")

</div>

Thanks for the help! Everything seems to be in order. If by setting setting from the actor bp to the anim bp you mean this:

 ![imagen_2024-10-21_223833286](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/f/8/df8726479d41239bd1bbb133a085719279be6668.png)  
Then yeah.  
I was just trying to fix some issues in the Anim graph and EventGraph. I Didn’t even open the controller or anything. And as I said, what’s really weird is that a similar anim bp that I didn’t even open and that uses different bps also fails its casts to its controller.  
It’s just that the more I look into it the weirder it gets:

 ![imagen_2024-10-21_223241235](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/f/60fd64bb90c630670588cbe3b4516a4f520b3628.png)  
Even though This cast is failing I’m still able to recieve the LookingDirection from the Controller and the character behaves accordingly when launching the level.

 ![imagen_2024-10-21_224313803](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/3/0/a30611bb617016576493bf3ff0861bfd73e1e904.png)  
It’s this second Cast that seems futile, even when I try to bypass the isValid node.

---

<div class="post-metadata">

**Author:** ![Glyphrr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/glyphrr/32/988812_2.png) [@Glyphrr](https://forums.unrealengine.com/u/Glyphrr)\
**Post date:** [October 21, 2024, 8:56pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/4 "2024-10-21T20:56:47Z")

</div>

This indeed is extremely strange, do you have different player controllers?

If you don’t, check that you have the correct player controller ( think it is that Edmon Controller ) selected in your game mode

If you do check that you are assigning the correct controllers to the appropriate actors.

---

<div class="post-metadata">

**Author:** ![Glyphrr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/glyphrr/32/988812_2.png) [@Glyphrr](https://forums.unrealengine.com/u/Glyphrr)\
**Post date:** [October 21, 2024, 9:05pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/5 "2024-10-21T21:05:47Z")

</div>

Also, I wouldn’t cast to the player controller on each animation update, casting should be used sparingly. Try casting to the controller after you casted to the Edmon\_NPC on the Initialize Animation event.

Use the Edmon Character Variable and try get controller from that and set that as a variable, then you can use that to get your variables needed to update the animation.

---

<div class="post-metadata">

**Author:** ![Mr\_AKIMBO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mr\_AKIMBO](https://forums.unrealengine.com/u/Mr_AKIMBO)\
**Post date:** [October 21, 2024, 9:14pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/6 "2024-10-21T21:14:00Z")

</div>

Yes, the correct controller class is assigned to the actor.

 ![imagen_2024-10-21_230411882](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/4/d/f4d3b81dae48de16b7c5fda05979e8aa3d714772.png)  
I believe the main issue is that the Get Controller From Pawn isn’t working. Probably something to do with the character bp. I did change the controller to none for a moment to test a thing but then I changed it back.

---

<div class="post-metadata">

**Author:** ![Mr\_AKIMBO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mr\_AKIMBO](https://forums.unrealengine.com/u/Mr_AKIMBO)\
**Post date:** [October 21, 2024, 9:16pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/7 "2024-10-21T21:16:42Z")

</div>

> [@Glyphrr](#):
>
> Also, I wouldn’t cast to the player controller on each animation update, casting should be used sparingly. Try casting to the controller after you casted to the Edmon\_NPC on the Initialize Animation event.

Yes, I just though of that and changed it. Which is how I found out that the Edmon Character variable is valid but the return of Get Controller isn’t.

---

<div class="post-metadata">

**Author:** ![Glyphrr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/glyphrr/32/988812_2.png) [@Glyphrr](https://forums.unrealengine.com/u/Glyphrr)\
**Post date:** [October 21, 2024, 9:23pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/8 "2024-10-21T21:23:21Z")

</div>

Yea that is wierd, might have to do a bit of debugging to see if the controller is properly getting assigned to the character.

If you would like you can share the project files with me and I can take a look from my side.

---

<div class="post-metadata">

**Author:** ![Mr\_AKIMBO](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mr\_AKIMBO](https://forums.unrealengine.com/u/Mr_AKIMBO)\
**Post date:** [October 21, 2024, 9:39pm UTC](https://forums.unrealengine.com/t/cant-figure-out-why-these-casts-are-failing-all-of-the-sudden/2079124/9 "2024-10-21T21:39:31Z")

</div>

That would be extremely helpful and generous by your part. If I don’t seem figure it out I’ll porbs share with you the files.
