How to access a variable from one Blueprint while in another?

Hello :slight_smile:

Pretty simple question: I have a Boolean in one blueprint class that I would like to access in a different blueprint class. I’ve tried casting but don’t know what to plug in to the object, or if that’s even the right way of going about this.

Any help is appreciated!

This changes depending on the blueprint you want to access, if it’s a class that’s defined in the game mode such as player controller, player pawn etc then you can get a reference to it by calling whatever it is (Getplayercontroller, Getplayerpawn). If it’s a spawned actor then, you can store a reference on spawn as well. If however it is simply an actor derivative that has been placed in the level (and you aren’t accessing it from the level blueprint), it can get a little more complicated. If you can’t get a reference from somewhere to that class, there is a node called Get Actor of Class/Get all actors of class, this allows the entire level to be scanned for an actor of a specific class and returns the reference/All references, these should be used with caution though as they are a slow operation, they are fine for getting a reference once and storing but should always be used as a last resort and never on repeating operations like timelines or tick.

It’s also worth thinking if you can send the information rather than calling it, for instance can the blueprint with the variable tell others the value, rather than them calling for it.

I would spend some time also looking into other means of blueprint communication too, if possible. For instance you can avoid casting completely by utilising blueprint interfaces, although you will still need to find a reference to that actor from somewhere.

You don’t need casting, just use direct communication:

I’m confused because in that video it looks like all of his communication is with casting

I was able to get it to work using Get All Actors of Class, but should I continue seeking an alternative? If my object is only in the level once is the scan still going to be as slow?

And out of curiosity, how would I “send” the information?

It’s fine to use sparingly, it’s all about picking your battles and while scanning the entire level for a specific actor is slow, if you do it once and then store the reference to that actor rather than using GetActorofClass each time it’s fine, it’s just something to keep in mind and helps you avoid “Death by 1000 cuts”.

As far as sending the information, it’s just thinking about how the variable is communicated to others. For example if “Actor A” has the variable and “Actor B” needs the information, you don’t always have to make “B” ask “A” for the information you can have “A” tell “B” in the same way, if it’s easier to get a reference that way. Of course it comes down to the specific case and I can’t tell you what’s best, it’s just worth considering all the angles.