How do you reference actors within a character blueprint

is there a way of referencing objects in the world and referencing them in the character blueprint?

Hey -

In the character blueprint you’ll want to get all actors of the class that you want to reference and then do a ForEach loop to access each element of the array. Drag off from the Array Element pint to cast to the class you want to access the functionality off and then you can call the function of that class. Here is an image to show the flow control in the character blueprint:

Cheers

Thanks man :slight_smile:

Hey ,

Thanks for your answer. it helped me getting through my blueprint problem. Right now everything is working however is still don’t understand what Casting does. Initially i had it set up just like you show in your screenshot but unreal told me that I already had those objects so casting was unnecessary. i removed the casting nodes and the blueprint sil functions. Why? In what situations do really need casting?

The example given was simply to indicate how to setup the casting nodes. Since the “Get All Actors Of Class node” specifically looks for actors of the specified class (in your case BP Char Anim) any actor in the resultant array is already of that type.

Using your screenshot as an example, specifically the Break Hit Result node, a good use of casting would be if you wanted to confirm what type of actor was hit. In this case you would wire the “Hit Actor” pin into your cast not to test “Was the actor hit a BP Char Anim actor”.

This is an old post, but I feel it’s still pretty relevant to my issue.
I’m trying to make what’s basically a button blueprint that my character interacts with using a line by trace. That button should then communicate to a block that represents a door to open (destroy itself for simplicity sake).

Using the answer given this works just fine, however, it seems a bit much to cycle through ALL actors of a class and then pick one. This also destroy multiple instances of that same actor if they are placed around a level. I know that by giving each seperate actor a tag you could make sure only specific instances of the BP are destroyed.

The question is: Is there a way to reference a specific blueprint that you have no ealier reference to (e.g. due to the absense of overlapping/hitting/using linetrace)? I have tried making a variable that references a specific BP, but that doesn’t work for me.

Hey -

In your case of a button that open a door, rather than getting a reference to the door when the button is pressed it would probably be best to add a variable to your button blueprint that holds a reference to the specific door it is connected to. For example, if you create a Door blueprint and a Button blueprint, you can add a variable of type Door to your Button blueprint and make the variable public. When you place the button in the world, you can set any door that exists in the level to the variable. When the button is pressed, the logic that controls the behavior of the door is run only for the specific door.