# Event on map load/switch

**URL:** <https://forums.unrealengine.com/t/event-on-map-load-switch/395154>\
**Category:** C++\
**Tags:** map-load, unreal-engine, question, CPP\
**Created:** [May 31, 2017, 2:12pm UTC](https://forums.unrealengine.com/t/event-on-map-load-switch/395154 "2017-05-31T14:12:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![solarisx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@solarisx](https://forums.unrealengine.com/u/solarisx)\
**Post date:** [May 31, 2017, 2:12pm UTC](https://forums.unrealengine.com/t/event-on-map-load-switch/395154/1 "2017-05-31T14:12:14Z")

</div>

Hi,  
I write a plugin which add some components to existing actors and reacts if they get unregistered. Now I need to detect if the user switches the map and do some work before they get unregistered. I can not place the code in the OnUnregister() of the components, because I only want to react if the map(or level) gets switched.

I tried to place a dummy actor in the current map and listen on its BeginDestroy(). This works, but would be useful only, if this is called before any other actor component gets unregistered. This does not happen.

Here a debug log which should explain the point in time to react:

```
<-- user double clicks in unreal editor content browser on a map to load -->
Cmd: MAP LOAD FILE="../devproject_4_16/Content/StarterContent/Maps/Advanced_Lighting.umap" TEMPLATE=0 SHOWPROGRESS=1 FEATURELEVEL=3
LightingResults: New page: Lighting Build
LoadErrors: New page: Loading map: Advanced_Lighting.umap
<-- Last point to react! -->
LogTemp:Warning: Actor component unregistered.
<-- To late; one of the interesting components already have unregistered -->
LogTemp:Warning: Actor component unregistered.
....
MapCheck: New page: Map Check
LightingResults: New page: Lighting Build
LogTemp:Warning: BeginDestroy <-- here comes the BeginDestroy event from the dummy actor. Unfortunately to late!

```

How to get in this tiny time slot after map switch begins?

Thanks for any help, solarisx

---

<div class="post-metadata">

**Author:** ![joeypark](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeypark](https://forums.unrealengine.com/u/joeypark)\
**Post date:** [June 1, 2017, 2:37am UTC](https://forums.unrealengine.com/t/event-on-map-load-switch/395154/2 "2017-06-01T02:37:50Z")

</div>

How about using FWorldDelegates::LevelRemovedFromWorld delegate?

---

<div class="post-metadata">

**Author:** ![solarisx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@solarisx](https://forums.unrealengine.com/u/solarisx)\
**Post date:** [June 1, 2017, 8:49am UTC](https://forums.unrealengine.com/t/event-on-map-load-switch/395154/3 "2017-06-01T08:49:19Z")

</div>

FWorldDelegates::LevelRemovedFromWorld does not fire in my case, but thanks for pointing me on FWorldDelegates! Was focused on Levels and Maps and did not thought of World.  
So I found **FWorldDelegates::OnPreWorldInitialization** , which is what I need.

Thanks very much!
