Casting between actors

Hey guys, I’m having a bit of a moment here. I’ve got got two Blueprints in my level that are both based on actor class. Each one contains different parts of my overall game system. One the general rules for the game, importantly for me one that is driving a day/night cycle and counting the days. My second blueprint controls the growth of a forest in the scene. I usually don’t have any problems casting to my hud or player character, but in this case, I just can’t figure out what to plug into the reference slot to be able to access the integer variable in Blueprint 1.

I know I’m just forgetting something simple, but I’m also wondering if I’m just thinking about this incorrectly and instead of sending that integer around to other blueprints, perhaps I should just be dispatching events? Thanks in advance.

Casting essentially converts vague class (Actor, Widget, etc.) into a more specific class (DayNightCycle, PlayerHUD, etc.). If you have an actor, you can only access things for the actor class, like ‘Actor Hidden in Game’, lifespan, etc.

The object for your cast needs to be a BP_MasterSystem, but in the form of an actor, an object, or whatever else it might be. An example of this is that if you line trace to something, and you have ‘Hit Actor’, it could very well be a BP_MasterSystem, but it is in the form of an Actor, so you would need to cast using ‘Hit Actor’.

Hey! Thanks for the fast reply, I partially follow you, but then you lost me. I’d tried this before, but after reading your message the closest thing that made since we setting the reference to just an actor variable, but that doesn’t work. So I think I’m still missing the point. If I was trying to get this info from the player controller/character it’d be no problem… or if there was an overlap or event involved. I guess I’m confused because this is currently running off of a tick event and should constantly check for this variable to change. Thanks again.

Here is the first actor blueprint that I’d like to send the integer variable from

Well, you need a reference to that specific actor (You aren’t setting that blank actor variable to a reference, so it is blank), so maybe if the blueprint collides with your master system, you can cast using the ‘Other Actor’. But you have to have some reference in one form or another. If there is a place where you spawn your MasterSystem blueprint, you could store the ‘Return Value’ as the reference, and somehow get that reference into wherever you need it.

There have been times (Like right now) where I pass references down through multiple blueprints. I need to reference my Day/Night system in my character blueprint, so it goes Level Blueprint -> Main Menu -> Character.

Ok, I thought I had something working, but I still can not for the life of me get the variable over to the other blueprint. I’ll have to keep hacking away at it. Thanks anyhow.

Easiest way (not most efficient) is to pass variables trough player pawn or player controller, because about everything can get their reference and can cast to it.
When you get that working you probably undestand idea of casting and you will extend that to other blueprints.

So in player controller create variable “grab_this” make it visible (small eye icon).
In blueprint you choose create nodes: “get player controller” > cast to “your player controller class name”
Then as player controller get value of “grab_this”

You have most basic communication.

Ps.
That accessed none error is when you have invalid reference, you need to have it pointing to some actor in level.
To get pointers to some blueprint (that must be placed in level!) do:
Get all actors of class “BP_MasterSystem”, result is array. Get element 0 from that array and you have valid reference.

pps. (years later)
accessed none error sometimes happens due to load order of actors. First determine it is because of it (make sure it is just load order, then make sure your code can compensate and retry to get valid pointers later etc). Then just inhibit that error until you got valid pointer (until referenced actor was loaded).

2 Likes

Thank you very much, your above post cleared up everything. Unless I missed something, I didn’t see BP to BP communication covered in the manual. But, I might have just missed it. In every other project I’ve built, most of my important variables were kept in the player controller. As you said, super easy to cast to. I just didn’t think grabbing the BP from an array. So thanks again for your help!

The problem with using ‘Get All Actors of Class’ is that it is very inefficient, and should be avoided as often as possible. If you do use it, use it once, and store the reference in a variable.

Thanks for the extra advice. I’m guessing when you say inefficient you also mean performance heavy? If I do just store the reference as a variable on eventbeginplay, and use that just once in the external blueprint, is that still considered bad form?

It’s fine to use it like that yes. That would be the main use, it would only be heavy on performance if you were doing it on tick for example, I think it actually warns against that in the tool-tip for the node.

Hmm just stumbled across this post. Sorry pixelvspixel :stuck_out_tongue: Had you linked me to this I could have told you how to do it straight away haha XD

So surreal to see this on the forums haha XD Glad you sorted it out :slight_smile:

i just save reference to very important systems into game instance.

awesome… i was just casting to player… i knew there surely had to be a work around… thanks.!