Cast to character always failing

Are you sure. that your Character is from class Player_character?
Could be that there is the wrong pawn in your scene.

That would explain why the cast always fails.

Bregards,

hi everyone I am trying to cast to my “player character” to get a variable called “has enough currency” for a shop I am making but the cast to player character always and I mean always fails and I can’t understand why.

screen shot 1 is of the cast to player character node
screenshot 1:

screen shot 2 is of the event tick node checking if the player has enough currency or not
screenshot 2:

screenshot 3 is of what happens when I press the button
screenshot 3:

thank you for reading and in advance for all help I really will appreciate it

yes I am 100 % sure

also I forgot to mention that the cast to works fine in other widgets such as my “HUD” widget to display the currency

never mind thank you so much I found the answer thanks to you thank you!!!

1 other question:
how would I spawn it in the world once the player has bought it?? (I’m talking about the rocket launcher)

I may be misunderstanding your question. You know how to spawn things in general right? Spawn Actor of Class node? That takes in a Location parameter that tells it where the new actor should appear in the world.

yes but how do I do that??

do you mean with the transform part of the node??

ok thank you

for the casting to the spawner (which is an actor) what do I use for the object??

For location use whatever you like, either a hardcoded location or a reference to another actor’s location.

What do you mean? This is a “Spawn Actor From Class” node, there is no “casting” to the spawner??

You would have to use something like “Get All Actors Of Class” which will return an array of all spawners located in the level, so if you have multiple this will be an issue. If you are doing this within a level BP you can easily create a reference to any actor including your spawner by selecting it in the viewport and opening the level BP, right clicking in the event graph and search for “create reference to selected actors”. But you need to get a reference to the spawner somehow to be able to get it’s location.

no I have a spawner in the game and I am casting to it to get the actor’s location

Looking at the blueprint, i see nothing wrong with that. The issue has to be somewhere else. Are you 100% sure that’s the exact class for the current player? Maybe you’re using a different one (like a stock 3rd person one, or another class you made besides Player_character). One way to check would be to do this :

See what name prints, and thats the class it’s calling. If it’s “Player_character” then there’s a bigger problem lol

I already fixed it last night after someone else commented but thanks anyway for your help

Was that the issue? You should edit your post with the solution for the next person. Glad you got it working though =]

Hi! Do you remeber the solution? I have the same problem…

1 Like