How to check if Level Instances have finished loading?

Hello I’m learning how to procedurally generate a level using instanced level streaming.

My question is how to check if the level instance has finished loading?

I want to make a simple loading screen, so before the level loads the game checks if the level is loaded.

Below is a snippet of the generation script, tell me if more info on the blueprint is needed I’ll post them as soon as possible.

1 Like

Hi Zellith,

This is what I did. I made a Macro (which is like a function but can handle delays and multiple exec outputs) which periodically checks if the level is loaded. The functions you want is “Get Streaming Level” to get a level by name, then “Is Level Loaded” to check if it’s loaded.

I hope that helps!

2 Likes

Polling is a good solution, as has suggested. Another solution is to use the OnLevelLoaded and/or OnLevelShown events, like this:

3 Likes

, thank you so much!

This is definitely the way to go! Thanks … now I just have to figure out why this event is not firing for me. :slight_smile:
EDIT: (never mind, I subscribed to the event after I started to load the level)

1 Like

This is horrible, don’t do this.

1 Like

Unfortunately, this macro cannot handle checking multiple instances of sublevel (version with instance as parameter instead of name). That’s it, you cannot hook it up to foreach and expect sane results. It will return pretty randomly (presumably after finishing one of sublevel instances).

The best way I have found is editing the delegate to support a output.

Hi, I’m trying to do the same thing using this solution with Bind Event to OnLevelLoaded but for some reason my registered event is never called but the level instance is loaded in correctly.

This is my code:

The EntryHallLevelName is just a variable of type Name that contains the name of the map/level want to load.

Does anyone have an Idea what is going wrong here?

Do you specifically want an instance? If not, you could use

image

Yes I need an instance - so I can’t use the node you suggested - because I want to spawn additional instances later (at different positions in the world) and unload them individually.

Ah… I could never find a way of knowing if a level had loaded. I ended up using a delay loop, and watching for the player start ( which I put there specifically ). That seemed to work.

Have you tried getting the solution discussed in this threat to work?

Of course. In fact I just tried again, it doesn’t work ( if you’re referring to the callback ).

I wonder why it doesn’t work for us but the people earlier in this thread reported it works for them. Is it just because of a different engine version (I’m using 5.1.1)?

1 Like

It didn’t work in 4 either, for me.

As far as I could tell, ‘get streaming level’ just returned the persistent level.

Also, I can tell you, that what the engine considers ‘loaded’, will probably not be what you consider a good deal :slight_smile: Things will still be popping up all over the place.

So I still recommend the ‘testing’ method.

Seems like the only choice if this doesn’t work after all. Registering a callback would be a lot cleaner though.

In case someone gets this to work, please enlighten us how.

1 Like

Try this, it works on my side:

protected:
	UFUNCTION() void OnStreamLevelLoaded();

	enum EActionId
	{
		AID_Loading,
	};

	enum ELinkID
	{
		LID_Link
	};
...
        FLatentActionInfo LatentActionInfo;
		LatentActionInfo.UUID = AID_Loading;
		LatentActionInfo.CallbackTarget = this;
		LatentActionInfo.Linkage = LID_Link; // have to be not equal to INDEX_NONE, and probably should be void* to ExecutionFunction bindable params
		LatentActionInfo.ExecutionFunction = FName(TEXT("OnStreamLevelLoaded"));
		
		UGameplayStatics::LoadStreamLevel(GetWorld(), EnvironmentMap, true, true, LatentActionInfo);

I was able to solve this problem by binding an event here: