x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.20
Tags:
more ▼

asked Jan 30 '19 at 03:02 PM in Using UE4

avatar image

Maverick_tango
249 3 4 7

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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)

http://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UEngine/OnWorldAdded/index.html

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:

http://api.unrealengine.com/INT/API/Runtime/Engine/Engine/EWorldType__Type/index.html

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

http://api.unrealengine.com/INT/API/Runtime/Engine/Engine/FWorldDelegates/index.html

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:

https://api.unrealengine.com/INT/API/Runtime/Engine/Engine/ULevelStreaming/OnLevelLoaded/index.html

more ▼

answered Jan 30 '19 at 10:51 PM

avatar image

Shadowriver
35.2k 921 166 1098

avatar image Maverick_tango Feb 01 '19 at 09:07 AM

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

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question