Level instance workflow

Hello, we have a project that use a lot of reusable structures, and found that Level instances was the thing that worked best for us in the beginning. However, as we go one, we have the need to pass some variables to the level instances, which was not as easy as I’d expected.

Additionally, when working on Level Instances, I’m also struggling with ensuring that the level is fully loaded. Optimally, I’d like to use an event like OnLevelShown, but I cannot seem to find a way to bind that event if I’m not dynamically spawning the instances. I guess polling IsLoaded is a solution, but not a pretty one.

Passing data down instances from “root→Parent Instance→ Child instance” seems rather difficult, so far the only way we have been able to access specific objects, is by comparing translations or other hacky solutions. This despite having the level instance reference, which I’d hoped I could access the internal actors from.

To me, this should be a simple use case, so I’m questioning if I’m just attacking this from the wrong angle. Does anyone have any experiences with working with Level instances?

I think youre attacking it wrong.

I hhink on games is always more effective to use push strategies instead of pull.

That means, its better to have an actor with a delegate that notifies when things are done than “waiting” for things to be done or checking.

Im away of my pc atm, but ive worked with level instances and i love them.

I know theres a global engine delegate for when a level is loaded. Im sure someone else will post it for me here.

But keep in mind ttat doesnt warranty that all is processed.

Actors’ beginplay is a box of chocolates, and i recommend not puttinc oneself in situations where youmdepend on them.

Eg. Theres an optimizaiton, iirc is newish, that allow objects to process their beginplay staggered or delayed across multiple frames.

Youll be in trouble there.

1 Like

Theres a way to load level instances where you obtain a sort of promise for it, i dont remember for sure, but im confident 70% that theres a delegate for loding finished.

Ive mode a plugin with tthat ill post it if i remember tomorrow.

Its not really a simple use case. The process of loading assets and initializing actors is rather complex and very lenghty. So by necesity everything is async, which is even more complex.

Passing parameters to level instances is really not what they are made for. I wonder if a big actor would be better. Or maybe some sort of manager on each level instance that holds soft refereces to actors.

Im struggling to imagine what are you trying to do.

You can get alr the actors in a level instance when working on cpp. By getting a ref to its world, then iterating the actors.

Though i feel you might have more succes fliping it around, and having a subsystem that provides the init data, and the actors query it. But you might have the same problem of beiing able to identify them.

1 Like

In my level, I have a bunch of template structures that we reuse. Inside these structures, there are even more structures that we reuse. These leaf structures are a collection of actors that has some functionality. Up until now, these has been independent, so no problem. However, recently we have the need to put some unique labels on some of the structures inside the level instances.

In the spirit of giving a simple example, imagine one level instance as a neighborhood, which has more level instances of houses. The game has multiple identical neighborhoods. Now I need to give the houses an unique address.

The quick and dirty solution was to have a manager that passes the labels directly to the actors by comparing the positions. As you can imagine, this falls apart really fast when we make some changes.

I think you’re referring to OnLevelShown(), which I can get from the ULevelStreaming objects. I think that should trigger once that level is loaded. Definetly interesting.

In this context, I’m not sure what push/pull would refer to. I assume that I should try to push my string from my level manager down to my leaf blueprint/Level instance. Though, you could call this a pull, since the leaf is pulling the string from my manager :stuck_out_tongue:.

However, my main issue is that I don’t know how to figure out which instance the actor came from. How do I know which actor I should push my string to?

I tried earlier to solve this with the level blueprint, but I have now realized that I have better access to StreamingLevels in C++. This could give me access to the OnLevelShown() delegate, which could solve the loading issue. Maybe I’ll find some way to sort my actors by levels there.

Edit: I suppose sorting the actors into Levels only solves it partially. I also need to know which object in the level it is. (House1, House2… etc.). It would be easy if I could use the display name, but that is being renamed into an unique name as far as I know.