[UE5.4] How do levels work?

Ok. So I learned a LOT in the past hour or so.

Loading a level takes time. A LOT of time. In C++, when you call OpenLevel, it needs to do a LOT of stuff and both levels will be active for a while. It needs many many ticks before the new level is ready. So I indeed do need to know when the level is finished loading. OpenLevel is NOT synchronous. Yes, it does a lot right away, but not everything. Not even close.

IOW, you can’t use a level immediately after OpenLevel() in C++. The funny thing is that I’ve seen plenty of people asking how to know when a level is done loading and there’s never an answer. Well, GameInstance::LoadComplete() will be called when the level is ready. OnWorldChanged will be called MUCH MUCH earlier. But this is the only reliable way I’ve found to get a reference to the new world/level.

I’ve now got the level kinda working. The player character is even at the correct location and I can move the camera around. Only problem is that the navigation system is sometimes null. Again, I believe this is a delay issue. It’s just not ready yet. Because if I put breakpoints in the debugger, it works fine. IOW, it’s had enough time to set itself up.

So I’m gonna look into seeing if I can detect when the nav system is initialized.

Anyways, huge progress.

edit: My PlayerCharacter has finally teleported to the new level. AWWW YISSS!!! It’s starting to work.

edit2: Argh… was using the wrong world for getting the nav sys.

WOOHOO!!! IT WORKS!!!

I can switch levels. Even the level instances work great.

3 Likes

When playing in the editor, everything works fine. But when running in a standalone window, Level Instances don’t load. I’m getting the event that it’s loaded but the actors are not in there.

I’ve tried both dynamic loading as well as static (ie. already in the level) and neither works.

Looks like there’s a bug with Embedded Mode. It’s supposed to put the actors directly in the main level. And it does so when running in the editor. But in standalone, the actors stay part of the level instance. So UGameplayStatics::GetAllActorsOfClass() doesn’t work on those actors. You need to manually get the loaded level and from there you can get the list of actors in the level instance.

There’s a thread about it here:

https://forums.unrealengine.com/t/getting-actor-in-level-instance

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