Which function or parameter is called when we load "NewLevel"?

Hello Guys,

I have previously used unity and in there was one function “OnLevelLoaded” , basically this method is called when ever new level is loaded !
So do we have something similar in UE4 ??
(Any parameter or function which we call while level is loaded and when level is exiting )

Using C++ function will be very helpful

Thanks in advance.

Generally there no need to do that in UE4, as in Unreal (and i don’t know Unity C# side of things to compare) world get reset on restart and level change, all actors (classes with prefix A and yest his include GameMode and PlayerControllers) getting reinitiated and all initiation events getting triggered, this way enigne makes sure that world is in clean state and and it kind of comes from UE origins of UT online matches. At point that this is happening level is loaded, only potential issue is initiation order which may be different for diffrent actors, but in general GameMode should be active first, i did some self registering code in past and didnt hit this kind of issue. You can also use that behavior to notify persistent code like UGameInstance that world got reset

But if this is not enough for you there OnWorldAdded even in GEnigne which is called when UWorld should have loaded level (note that this returning delegate which you need to bind to)

Note that also in editor this will be called not only when game starts, but when any viewport is opened as each requires seperate UWorld. You can identify which one is by checking WorldType varable in UWorld:

this shows how your code is essentially extension of enigne code itself, and your code becomes part of editor code when it runs in editor, always remember that.

There also set of verius events in FWorldDelegates but created here will be called when UWorld is create in constructor, so watch out

The big exception to what i mentioned in the biggining is level streaming which really requires this event as addign level to the world it wont reset main actors in persistent level, ULevelSteaming that is created (and you can detect if it been added in events above) has level loaded delegate:

1 Like

Thanks @anonymous_user_f5a50610 , This is exactly what is was looking for. And congratulation forgetting in weekly top KARMA earners.