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?
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.
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.
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.
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: