How to change variable of 2nd, or later spawned actor of class?

I just can’t seem to find a proper way to cast to a later spawning actor of class. The node of “Get All Actors of Class” only gives me an array of all currently spawned actors. Now I know it’s not good practice to use it all the time, but at the moment I don’t know an alternative way to do this.

I have an “Endless runner” kind of game where the game spawns a new obstacle after the player hits a trigger. The player can move forward in 5 lanes. The obstacle of that class that is the closest and infront of to the player should glow.

Right now the glow is triggered by a boolean “StartGlow?”. If the player hits this obstacle, the first upfollowing obstacle of the same class should start glowing. And if that one is hit, the next upcoming one. Etc. etc.

By using “Get All Actors of Class” this KIND OF works. Player hits the object, the next object of class starts glowing by adding +1 to “Hit Obstacle Count” Except when new actors of that class spawn that were not in the array at first it suddenly stops working. Which makes sense to me. Except, how can I make it so this functions properly?

The print string is just there for testing to see the name of the actor it’s trying to cast to which results for the very first object to “BP_FloorTile_Obstacle_Randomized_C_0”. I wish I could of just casted by using a string and make it so everytime “Hit Obstacle Count” Goes up. You’d go from casting to “Randomized_C_0” to casting to “Randomized_C_1”

How are you spawning the new actors in? Depending on the setup you could allow the overlapped actors to spawn a new instance of themselves and through this method pass the ability to “glow” to the newly spawned actor.

I am spawning the obstacles in through the Gamemode blueprint.

In the function “Add Floor Tile” I have it set up so that it grabs a random actor from array (The obstacles in my case) and spawns them attached to each other.

That sounds like an option but I am not sure it will entirely work. As of now, I have it set up so it spawns 6 random actors from array at the start. Not all these actors have the ability to glow as they don’t all require it. These actors will also destroy themselves after a while to keep performance.

Instead of using the “Get all actors from class node” give your gamemode an array variable to keep the references of your tiles.
The Spawn function gives you an output reference, after spawning add this actor reference to your array.
To get the indices:
Your player overlaps one tile->inside your pawn “Event Actor Begin Overlap Event”-> take the “other Actor”-> Cast to your floor class->If successfull-> Get gamemode-> use the “find” node from the array to get the actor’s index of the array add +1 and you have the next floor tile, which you can now set to glow… Don’t forget to remove the floor tile from the array, when you are deleting it, so you won’t have leeks.

Thank you so much! This is what I needed, I have slightly adjusted it for my needs. I did as you said, made an array within the Gamemode where they are spawned and if the actor has a tag “Glow”, add it to the array. Then in my player blueprint I made sure that index 0 of the array has the boolean “StartGlow” is true. Then when player hits said obstacle object, cast to gamemode, delete index 0 and set “StartGlow” to false.

So I slightly adjusted your idea but it was definitely what I needed! Thank you so much, now I can finally continue again!