What object to pass in when casting to an actor in a level blueprint?

I have an actor called Brain_Turret_right that has a function. Its function is to shoot a bullet.

In my level blueprint, I want to make it so that every x amount of seconds, it calls the Brain_Turret_right’s shoot function.

How do I cast to Brain_Turret_right from the level blueprint? What object should I put in the cast node? In the example picture given, I plan to simply connect it to EventBeginPlay just to see if it works.

Thank you for any input.

You need to pass a reference of the turret. Yet if you have a reference you don’t need to cast.

In Level BP you’d create references to all the turrets. Get all Actors of class is the typical (wasteful) approach.

Better option is to not do this in the Level BP, instead do it in the Game Mode. Use Event Dispatchers.

2 Likes

Have to somewhat agree with RevOverDrive in that don’t do it in the level Blueprint.

Its a trap! :slight_smile:

My recommendation would be to have another Blueprint make reference to the turret as well as have a public variable for xSeconds on that other Blueprint. That way you place the turret on the level, place this controlling Blueprint on the level and then link them together using the exposed properties on the turret controller.

My example… …I have a Blueprint that controls the lights in a cave. CaveLightSwitchBP. It has two public variables: TriggerBox and RectLightParent. In my cave level I place an instance of CaveLightSwitchBP, a TriggerBox and at least one RectLight. Then I link everything together using the CaveLightSwitchBP public variables. The desired functionality is in CaveLightSwitchBP.

1 Like

If you select the turret in your level, then go to level blueprint, right click you’ll see an option to create a reference to that actor. It will work with any actor in the level.

1 Like

You could also make the “shoot every x seconds” function inside the turret blueprint and use a boolean to control if it does shoot or not per instance, that way the function will be easy to reuse in other levels.

This is what I used for my specific issue, thank you a lot!

1 Like

Glad it helps.