Is there a better paradigm for locating objects in newly-loaded levels than using delay nodes?

For the longest time, whenever I’ve needed to find a specific object in a level I do something like this:

It very technically works, but it’s practically an antipattern: using the Delay node to keep GetAllActorsOfClass from running until the level finishes loading is unacceptable and error-prone, and using Get All Actors Of Class + iterating seem pretty wasteful in and of themselves, since I’m doing a very large amount of work to locate a single object. However, I’m having an awful lot of trouble thinking of alternatives; I could make the desired object locate my main logic actor in its BeginPlay, instead of looking for it from the logic actor like my screenshot demonstrates, but since all of the logic actor’s execution after it streams the level in requires this reference, I have the same exact timing issue. I’ve been struggling with this all week, but for the life of me I cannot think of a reliable way to do this without the delay node… is there an obvious design pattern I’m missing here?

You could have the logic actor spawn this particular actor itself or you could start a timer. Every tenth of a second or so you iterate actors to see if it’s the actor you want. It’s a lot of iterating but I doubt you’ll have that many cutscene actor types in a given scene. Then if it is you can clear the timer and execute the rest of your logic. It’s still on a timing thing but it’s recurring and will eventually happen as opposed to a delay which may not be enough time to wait on a slower computer.

Streaming levels also have a property “Has Level Loaded” you can check. If it’s true, the actor is already in play so you can be sure you can grab a reference to it. Again, you can check on a timer.

Ooh, that’s a really good idea… so to be clear, you’re saying create some FindCutscene function, running it every 0.n seconds on a timer, then having that function clear the timer when it locates the actor to ensure it won’t keep running once it locates its target?

Exactly! Alternatively you can have all of the actors in your levels inherit from a blueprint that register themselves with the GameMode on begin play, that’s what I do. But that’ll require reparenting all of your blueprints.

Oh hey, that’s a really neat idea, I’ll play with that a bit later if I can get the order of operations to work out… in the meanwhile though your suggestion worked perfectly, thank you again!! :slight_smile:

You’re welcome!