Open level by name works in editor but not after packaging?

This simple thing is puzzling me. I have a button to open a new level, and when I click it, it works if I’m playing in the editor, but if I select (Quick Launch - My Computer) or even package the project, it won’t load the proper level, but the Game Default Map.

if I set the game default map to none, it won’t load anything, will say level ’ ’ wasn’t found.

what could possibly be wrong?

Hmm, should work just fine. Make sure there’s no empty space after ‘Leve11’ =)
You can always open level by reference. Probably.

Yeah it’s so weird, the name is right, no spaces or anything.

I would use the open level by reference, but how do I store a level reference to my save game anyway? If i promote the level reference to a variable, it creates a “world soft object reference”:

image

but if I create a variable from scratch (so I can store it elsewhere), I can’t find that type of variable.

1 Like

You have to add maps explicitly when packaging. It’s annoying. Otherwise they’re left out.

Project Settings > Packaging > Advanced

3 Likes

wow thanks. this is so weird. I spent all day burning my brain trying to figure this out, would never have imagined.

turns out that even adding each level individually to that list didn’t fix it.

in the end what got it working was to check “cook everything…”

image

I have no idea why this is happening but doesn’t seem like a proper solution

1 Like

@JaredTherriault Is that a new thing in 5.0? In 4.27 you didn’t have to do that.

Definitely not new, I’ve always had to do this in projects with more than 1 level.

1 Like

That’s odd, I have a project running on 4.27.2 and it opens levels by name just fine. I never created any array of that sort.

I guess the engine just prefers your company over mine, that’s all.

You are correct, that’s not a proper solution, if you have many unused maps in your content folder you have to add all of them to the blacklist below that settings, otherwise the package size will be huge and the build time could increase a lot.

The approach suggested by @JaredTherriault is correct, it’s better to whitelist all the maps you need to be sure that all the levels you need are selected (in 4.27 AFAIK Unreal used to build all the levels by default if that list was empty, I don’t know if something has changed)

My doubt is: are you writing the level path correctly in the whitelist?

It has to be something relative like “/Game/Folder/LevelName”

I’m currently using “load level by name” in an Android VR build with this setup and it’s working just fine

is it working on packaged projects though?

Mine works fine in the editor, but not at all after packaging.

Really weird since I created a blank project, added two mostly empty levels, and set up a key press to open the other level. the most basic setup possible. it worked in the editor, not after packaging.

I thought I did, but apparently I didn’t, or maybe the path was wrong. Just tried again and it worked, so thank you

1 Like

Yes, it’s up and running on Steam. The way I have it, I have an array of level names as a variable in my GameMode, and it’s just level names, without “/game/maps/” etc. When I need to load the next level, I find the current level name in the array and open the next index. But I haven’t setup anything in Project Settings at all.

2 Likes

I can confirm this. I have a 70 level game but I don’t even have any arrays of the levels at all OR anything set up in Project Settings. I just name my levels 1, 2, 3, 4 etc. Then when player finishes a level it will get the current level name (eg ‘1’), then convert the ‘Name’ into a ‘String’, then to an ‘int’. Then it will increment it by 1 (so we get ‘2’), then change that back to a ‘Name’ and save that into the SaveGame and load level ‘2’. All works in PIE, Standalone and Packaged Game (Development and Shipping) no preblems at all.

2 Likes

If you have nothing set up in Project Settings you are probably packaging all the levels in your project inside the build (AFAIK this is the default engine behaviour).
White and black lists are used to avoid this and reduce the build size, if you have asset packs inside your project and they have a showcase map with all the assets, all the assets present in these maps will be packaged, but maybe you are using only 2 or 3 in your game.

In this case OP was not able to open the level because he had errors in the path of the level included in the whitelist, so the level wasn’t present in the build and he, obviously, wasn’t able to open it.

2 Likes

Yeah I don’t have any asset packs included in my project. All levels are mine and are needed, so should be ok. Thanks for the explanation though XD

1 Like