how do i get a reference to my own level inside an actor or widget

im not totally sure how to explain it, so ill just write what my situation is.

Im having an issue with garbage collection, and to help with it i want to encapsulate all my different scenes into individual levels. for example, a level for the main menu, and a level for the main game. iv been able to successfully do this with Open Level (By Name), but the issue is that its too slow.
Im moving away from a one level system (which was instant) to a multi level system, so i dont want this to be perceived as a performance downgrade by the people using my program (even tho technically its fixing a garbage collection/memory leak issue).

I discovered level instances work for this case. there is a small bit of lag, but its considerably better than outright loading a new level.
The only issue is that i need to be vary careful with how i spawn stuff into the world and how i manage my level instances.
Ideally id have one base/core level that does nothing other than initialize the main menu level, and then the main menu takes everything from here. The only issue is i cant seem to be able to access the main menu level as a data type, be able to cast it, or really do anything with it.
what would be really nice would be to destroy the level instance inside the level instance itself (get actor outer, cast to instanced level object), immediately after loading the next level instance. for example, i load the main game level, then immediately destroy the main menu. because they are all children of the base/core level, i would think i could do this safely.

anyways, situation explanation out of the way, anyone have any ideas how i may be able to do this?

1 Like

You can talk to a level BP using dispatchers, but it’s much easier to just put an actor in the persistent level, and talk to that.

You can have a level manager object in the persistent.

i could possibly try something like that. it may work, but i think ill have issues with GC in that case. for whatever reason my unreal engine hates garbage collection. ill see and keep you posted with what works

1 Like

in the end i just stuck with Open Level (By Name). trying to use an actor inside a persistent level caused issues with garbage collection somehow. idk. im really not sure why this is the case, but i suspect a reference was being created somewhere erroneously, and no matter how much i manually destroyed references, the erroneous reference would stick around.

when using Open Level (By Name) i just used it in a place where a stutter was going to happen anyways, making the few hundred extra ms of stutter unnoticeable. not ideal, because the garbage collection issue is still an issue when swapping between scenes in the same level, but once the level is swapped it would totally be cleaned up.
if someone was a goober and jumped between scenes in the same level, they could potentially run into memory issues (assuming 16 gigs of ram), but that would take like 20 mins with an auto clicker, so im not too concerned.

im gonna mark your answer as the solution tho, because i have a feeling it would be the right way of doing it in other peoples projects. it didnt work for me, but my project is weird

1 Like

Good luck :slight_smile:

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