This has been racking my brains and I’m starting to believe its impossible lol
Well there’s many ways to do this. In my project I have a “MyCharacter” BP and a “MyEnemy” BP (which handles all my standard enemies). I transfer all sorts of info back and forth between them by different means. When the enemy sees my player using the PawnSensing compnent, you can get a reference to the player’s actor there and then hook that into the Object tag on the Cast node.
Or you can use a number of other ways to do it. Trace events, overlap events, you can even get a reference when you spawn an actor if you’re spawning it from the original actor. When I begin my project I create a HUD widget for the player and grab the reference to that widget and set it to a variable right then so I can use it to update my HUD whenever I want.
In essence, you need to reference that actor somehow so the casting actor knows which instance of that character is being referenced.
What are you trying to cast from, and cast to, precisely? If you already have a reference to an actor, it makes no sense to cast it to an actor, because it already is an actor.
Listen I have an actor blueprint that contains a trigger box. When the trigger box is called I cast to another actor blueprint and I want to get a Boolean variable from it. Nothing works for the object. Nothing at all. The actor I’m casting to from the trigger box is a secret collectable. So it is just a mesh inside an actor blueprint.
You can just have the collectible BP have the trigger box and in engine, double click on the trigger box and you can move the one component wherever you want without moving the whole actor. In the BP, have an event on trigger box overlap -> cast to player BP to make sure it is the player walking through it and then you can have whatever you want to happen.
Thank you you are the first person to offer a true alternative that would work. The thing is the trigger box im using is for the end level trigger and this means I will have 2 trigger boxes this way one for end level and one for the secret collectable. It’s to make sure u finish the level before it saves the collected secret. Im sure I will come across this problem later on at some point tho. Is there no way to cast to an actor blueprint from within an actor blueprint to get a variable?
This should help you accomplish what you want to do. However note that I am new so I’m sure there’s better/appropriate ways to do this.
This is done inside the BP that you’ll be overlapping , in your case your trigger boxes. And the BP_Receiver is the blueprint that you’ll want to get your data from
As mentioned above, there are many ways to cast to another actor/BP. You just need to make a reference to it. Having two trigger boxes in one BP is perfectly fine, as they work independently from one another.
I mean, you really didn’t supply any information on your original post, so I’d say I did a pretty good job of giving as much info as I could in response. But here’s some more about what I think you’re trying to do.
Attached is an image of an actor blueprint. “MyCharacter” is also an actor blueprint. I have a collision box created as a component in the blueprint from the image. The “actor begin overlap” event will trigger whenever any actors enter that collision. The collision is really just there to verify that something can overlap with it since it’s collision settings in the details panel (on the right side of your screen when the collision box is selected) are set to OverlapAllDynamic.
So when another actor walks into that collision box the cast will happen. What this does is essentially sends out a check to see if the overlapping actor is that type of actor and if it is, your cast will succeed, continuing with the code. If not, the cast will fail. Much like a branch node.
Once your cast is successful, you can use the “As My Character” pin to get any information you want from the MyCharacter blueprint. The simplest way is to drag from that pin and start typing in whatever you’re looking for. In my case I just typed “is alive” and my “isAlive?” variable showed up on the list. Now I have reference to anything I could ever need from the MyCharacter blueprint.
If you need to send information the other way, TO the MyCharacter blueprint in this case, you can do it by changing variables to reflect whatever you’re trying to send, or even give that other actor a reference to the first blueprint by creating a variable to assign “self” to from the original blueprint.
Now if that isn’t enough information to get you going then I must be misunderstanding the situation and I apologize for not being more helpful than I was. Good luck!
If you get all actors of class it gets the thing your “casting” but you need to make it a variable so you can get the actors variables. This works better than casting actors, for me