Change the value of a variable of a character upon a specific Level Blueprint's EventBeginPlay

I am working on a 2d side scroller game. In this game, I have a character, 2DSidescrollerCharacter. This 2DSideScrollerCharacter has a variable I made, called “current_level_name”, of type Name.

The purpose of this variable is to change to whatever the name is of the level that the character is currently on. For example, if the character has begun level 1, current_level_name will be “Level1”. If the character has begun level 2, current_level_name will be changed to “Level2”.

I plan to accomplish this by doing the following: Every time a specific level is started, via level blueprint → EventBeginPlay, I want to set the current_level_name to be “LevelX”. I want to put in the number, X, manually/hardcoded, I don’t feel like making that any more complicated.

I am having trouble doing this however. Currently, I feel as if I must cast to 2DSideScroller character in order to actually be able to change the variable, and I likely need to get all actors of class from 2DSideScroller Character. I know how to get all of the actors from class 2DSideScroller character, but if you look in my attached image of my work so far, I don’t know how to cast to 2DSideScroller character without an “Object.” Am I going in the right direction, and if so, what do I need to do to accomplish my goal, or am I doing this completely wrong?

Thank you for the help. I appreciate any input.

image

In your case, you used GetAllActors, which returns an array, but then you did nothing with the array.

If you wanted to do it that way, you would need

This worked. Thank you for your help, I truly appreciate it.

1 Like