Download

The best way to reference an object?

As an almost completely inexperienced developer trying out Blueprint I found it hard to wrap my head around why I just couldn’t drop in a reference to another actor in a Blueprint and trigger custom events/get variables etc from it, 'til I got it explained. The reason being, if there are multiple actors of the same class in the level Unreal need to know which one to deal with. So this is how I go about it right now whenever I need to communicate with another class from a blueprint:

6a7fd160193cc0513721e3b3dec9dcb9fe2fa1b6.png

If there are multiple actors of the same class, I get all actors of the class, which makes an array (Which, as far as I have gathered, is just a list of all the actors in the level, with the first one created having the index of 0, the second one 1 etc, someone correct me if I’m wrong), plug that array into an ForEachLoop, cast to the class and trigger the custom event to each actor in the array.

9eaefe03bf0ec51dffb4862ab8f7590038580c26.png

If there’s just one actor of that class in the level, it’s index will be 0, so get a reference to that actor in the array, cast to the class and trigger the custom event.

Now this works fine, all I want to know is if there is a better way to do this. In the tooltip for the “Get All Actors From Flass”-node it says “This is a slow operation, use with caution”. Now that might not be something to worry about in my small test levels, but say in a full game, will using that node frequently cause some performance loss?

One thing I haven’t looked into much is Blueprint Interfaces, so my answer might just be there.

Sorry if this is somewhat unclear, communicating between Blueprints is just the thing I’ve had the most problems wrapping my head around, so I just wanna make clear I’m going about this the right way!

It might help if you explain what you’re trying to accomplish, since there might be better ways than using Get All Actors From Class.

I can’t speak for how the nodes would affect performance but I can tell you (from what I have experienced) how interfaces work (the dirty explanation), you make an interface which holds a single, or several functions which can have both only inputs, inputs and outputs or only outputs, note that you will always have the exec.
You can implement the interface on any blueprints you want to make use of the interface and (depends in how you set up the interface functions) for example, call blueprint events from one blueprint in a completely different one, you can also send variables through interfaces or use it so set varibles. Again this is just a dirty, quick explanation but hopefully someone more experienced or perhaps even a dev have a better answer for your specific quesition :slight_smile:

Interfaces is a way to send events to another blueprint with any custom parametres. You still need cast the target blueprint.

but your problem is in fase 1 ,interfaces work in fase 2

  1. Find the blueprint/actor
  2. Send event or set/get any variable funcion.

If you use Get All Actors From class only in the begining, when the level is loaded, they are not perfomance problem.