Best way to wait for certain actors to load

I have a pretty basic game where a level will have 5 important actors that I need to be there before it can start. I look for these actors in the Gamemode BeginPlay trigger. This works fine in PIE, but when testing in a build (Dev or Ship) my trigger can’t find the actors. Yet when the level visually loads I can see them.

After a lot of searching and trying stuff it turns out PIE has the actors “always-/pre-loaded”, so on Gamemode BeginPlay they were immediately available. In a build they take some time to load and are usually/never available at that trigger. So I made a system where, every time one of the 5 relevant actors load (they have a specific class and are marked with 5 specific Gameplay Tags) I will announce this to the Gamemode which will then check if all 5 have been announced yet. Only then will the game start.

I find this to be a little clunky, so I wondered if there is a better “trigger when these specific x actors load” or “trigger when one actors of each of these Gameplay Tags is loaded”.

1 Like

I totally get your frustration and the issues. I would say that you probably want to look over all of the assets that need to be loaded. If they take such a long time to load I would suggest looking into splitting functionality into components that are place on the actors. You can asynchronously load in them during the game load.

Also, loading screens, or fading in the view are used specifically to load in assets or hide that they haven’t been loaded.

There are functions that you can use to check if an asset have been loaded: Is Asset Loaded | Unreal Engine Documentation. I would use these if you don’t find that the other alternatives are good enough.

You could technically load in the 5 important assets as soon as the user press the .exe file to launch the game. You can keep the states and other things in the game instance which is loaded at all times.

Thank you for your reply. But nothing here is taking a “long time” to load. Everything is pretty much there immediately (it’s an incredibly basic game with just a couple of cubes and a sphere I move around). It’s just that the order of triggers prevents me from knowing WHEN those 5 actors are loaded.

its definitely a tricky one

i like to just control the load order so for instance if they’re important have them spawned by your gamemode that way your gamemode knows when theyre loaded and can start the game after.

a simple way is to use a timer or loop to constantly check if the required actor is valid, its kinda crappy but only done once on gameload

Perhaps some more info:

The actors are part of the level. My Gamemode looks for 4 walls (Tag Wall.North, Wall.South, …) and 1 Pellet (Tag Pellet). Using the space between the 4 walls and the size of the Pellet it will calculate how many spaces the playboard has.

Just to say: the 5 actors are part of each level. So having the Gamemode spawn them is the opposite of what I want to achieve.

But I guess there’s no better way (yet). Perhaps something for a plugin…

and whats dependant on them loading?

keep in mind using the gamemode for level specific stuff means the gamemode wont work on other levels.

there are better solutions but for an easy fix use a validation check on a delay loop to get the references

The Gamemode only looks for actors with a specific Gameplay Tag. These Actors can be anything at all. They only need to have a bounding box that I can analyze. In that respect the Gamemode is NOT using level specific stuff.

Maybe I’m doing something “wrong” here? How would you implement conveying information about the level (play area, starting positions of non player pieces) to the Gamemode?

Maybe I can put the waiting logic in the level and then pass it to the Gamemode once done (but that would mean duplicating it to every level)?

what about loading those objects manually? youd be able to have a reference of the objects and be able to know for sure they are loaded.
not as easy as “plop down actor. im done”, but it would give you alot more control over the actors.

to elaborate, you make an actor whos only job is to spawn actors. when all the actors are spawned, it sends a signal to other actors that its done and the game continues from there, just with you having all your references.

alternately, you can use the get all actors of class node. its totally fine on small projects where you are only dealing with a few tens of actors (or even a few hundred), or when you arnt using it with tick

It’s possible of course, but that would take away a lot of the userfriendliness of the level design. Where it doesn’t need any code to function besides marking those 5 actors. And the Gamemode then “discovers” the level as it is loading in.

In the end these are all fine suggestions. But they all feel as clunky as my own. So the answer is “no, there’s (probably) no better solution”.

Which strikes me as odd, but hey. That’s the way it is.

how are you loading the level? is this on first load (ie, you are just letting unreal handle it), or are you manually loading the level?

Yes, first load. I currently only have one level and it loads immediately on startup. I added "Print Text"s to the Actor’s BeginPlay triggers so the Development build would show me and you can see the messages popup. Quite fast, but still later than the level’s BeginPlay trigger.

Do you think I need a “Main Menu” of sorts before loading the level?

im unsure, tho are you intending on having a main menu in the future? it may be worth while adding it now, even if its just to resolve this issue.
in my case, because my program is all procedural, i was able to load in everything from a single actor; it handled all the spawning of literally everything and allowed me to get the references for everything in my level quickly and easily.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.