Download

ULevel as a UProperty

I was trying to add a ULevel as a UProperty, which compiles just fine.

However, I can’t actually set the value in the blueprint editor. No search results show up, and I can’t assign the value when I press use selected asset from content browser.

I might be able to get a reference to the level through C++ somehow. I can get a reference string to the level and it looks something like this: World’/Game/Environments/Test/TestLevel.TestLevel’

Before I go down this road, is there a good reason we shouldn’t do this?

A bit of background on what I’m trying to do:

Random level generator. I want to make chunks of levels that get put together in random arrangements. So far, I had success by using actors and placing components in the blueprint editor, but it’s just not the same as the level editor. I can’t place volumes easily, and in general, the editor’s interface is much better than the blueprint editor’s component editor. Just try making a mini level and you’ll see what I’m talking about. I was hoping to access the ULevel’s Actors array and use that as a template to spawn real actors in a randomly generated level. At the moment, I’m using the AActor’s components array as a template to spawn static mesh components, lights, and other things in the world.

I also failed to extent ULevel itself, so I was hoping to at least make an AActor that contains a reference to a ULevel and I could configure those easily from within the editor.

What you would want to use for the type is TAssetPtr<UWorld>.

Having a direct reference to a map/world/level would be extremely problematic because the direct reference would result in the map (and all its dependencies) always being loaded. By using the TAssetPtr you can get a picker and choose which map you’re interested in but not require it to be in memory.

What you are talking about is doable but I don’t think the approach of using the actors array as a template for spawning other actors is likely to work out for the best. Fortnite does something not dissimilar by having a base level with points where randomized elements are spawned in and they use the level streaming system to accomplish this though I don’t have the full details at my finger tips.

Oh thanks. In my case, I have different rooms that are going to be connected together in random arrangements, so I’m not sure I can really do level streaming.

I’m thinking I’d do what I’m doing now with actor components. I have a 3d transform in the world where I’m placing the room. I then go through the Actors array in the ULevel and spawn them relative to that transform.

I just hope that the ULevel goes out of memory properly later when I don’t need it anymore. I might try this way later though, for now I’ll stick with my current approach.

Both ways seem a bit hackish in a way, but It’s the best I can think of short of making a special editor myself for rooms. Back when I was making this game in my own engine I was designing rooms in Blender and exporting transforms out that way.