Custom blueprint always failing to cast

I have been unable to figure out why my cast always fails whenever I try to do it with blueprints that I have created. It works whenever I cast to the HUD or other things Is there a way without interfaces or similar things to cast and be able to call a function from another blueprint.

Here is a picture of what I have. The Receiver is a blueprint variable type in the picture. I have tried an actor variable but it doesn’t work either.

Is the BP you are trying to cast to a “Recier” or a “Reciever”? Is it possible that you in fact have two different BPs with similar names, thus failing to cast to one of them when you actually expect to cast to the other one?

It is just a misspell “reciever’s” value is the “recier”. (Im not the best speller)

Hi Lewa1000g,

In the get pin for your Receiver, did you make sure that the variable type is that of actor “Recier”?

The variable type is Recier_C which I don’t know is if that will change anything but I will provide a better picture so you can look.

How/where does the Receiver variable get its value assigned in the first place?

If there is nothing else going on in that BP, that we cannot see, then you are effectively trying to cast an uninitialized variable, and that will not work.

Can you do an IsValid check before the cast?

in the details pane, if you hit the downward arrow just below replication, is there another dropdown menu that has a specific actor in it? If so set that actor in the dropdown menu and try it again. the IsValid check mentions is also a great idea!

I tried to use the Is valid thing and that still did not work so I tried to have it be type blueprint and have recier as the variable in it. Now it will go through the is valid but it will still fail the cast. Also I don’t see what you are suggesting when I hit that arrow, I will attach a new picture of what I have so you can take a look, and let me know what im missing.

Also Thanks for the help

Hi Lewa1000g,

The image you posted did not come through, can you try to repost it so I can see what is going on? Thank you!

Hope this works, also thanks for the help

Hi Lewa1000g,

I was referring to the default value, which you can see in the bottom left of the image. It looks like you have it set to Receir which means it must be something else that isn’t picking this up. What is happening when you hit r specifically?

When I hit r it will basically check if the variable is valid which returns true but then it goes to the cast to recier and then it fails. I have it print string to tell me what happened. The actual function in the other blueprint is not begin called right now as it will fail. I have also included the recier blueprint in the picture below so you can take a look, along with the flow of what is happening in the blueprint.

Hi Lewa1000g,

Ok, what you have to do is add a “Get All Actors of Class” and a “ForEachLoop” node, and plug them in between your cast to and your isvalid. The cast is failing because it doesn’t have any specific instances in the level to refer to, so you use a get all actors of class to determine how many there are and the foreachloop to determine which one you want to perform the function on, or to do them all. Here is an image of my sender set up:

If you set it up this way it should work.

Thank you so much, I really appreciate your help.

Happy to help! I am going to mark this as answered for tracking purposes, please let me know if you need further assistance with this.

I had a cast fail, and it turned out that renaming a corresponding structure variable name, which contained spaces, resolved it.