# World Composition: Event when a level is loaded (C++)

**URL:** <https://forums.unrealengine.com/t/world-composition-event-when-a-level-is-loaded-c/448161>\
**Category:** World Creation\
**Tags:** level-loading, unreal-engine, question, CPP, World-Composition\
**Created:** [May 1, 2019, 10:03am UTC](https://forums.unrealengine.com/t/world-composition-event-when-a-level-is-loaded-c/448161 "2019-05-01T10:03:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flemmard](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flemmard](https://forums.unrealengine.com/u/Flemmard)\
**Post date:** [May 1, 2019, 10:03am UTC](https://forums.unrealengine.com/t/world-composition-event-when-a-level-is-loaded-c/448161/1 "2019-05-01T10:03:00Z")

</div>

Hello,

I’m trying to build some kind of data driven game (with NPC’s and such). I’d like to spawn NPC’s only when their level is loaded.  
I’m using world composition (needs to be some kind of open world game).  
But i’m not seeing any event noticing me that “hey, this level has loaded now!” and “this level has unloaded!”  
Does this kind of thing exists?  
Or that implies that i’m doing the loading stuff myself?  
(I mean, without adding code to every single level to trigger that…)  
Thanks !

Flem

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [May 1, 2019, 12:53pm UTC](https://forums.unrealengine.com/t/world-composition-event-when-a-level-is-loaded-c/448161/2 "2019-05-01T12:53:57Z")

</div>

Hey, you could simply hook on your GameMode code “BeginPlay” it’s called when the world is initialized

else if it’s with level streaming, you can use these events ( can be hooked in beginPlay Aswell i guess ) :

```
	ULevelStreaming* level = UGameplayStatics::GetStreamingLevel(GetWorld(), *MapName);
	level->OnLevelLoaded // with AddDynamic
	level->OnLevelHidden
```

---

<div class="post-metadata">

**Author:** ![Flemmard](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flemmard](https://forums.unrealengine.com/u/Flemmard)\
**Post date:** [May 1, 2019, 1:01pm UTC](https://forums.unrealengine.com/t/world-composition-event-when-a-level-is-loaded-c/448161/3 "2019-05-01T13:01:59Z")

</div>

Yeah but this only procs when the whole level is loaded, not every sublevel?

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [May 1, 2019, 2:57pm UTC](https://forums.unrealengine.com/t/world-composition-event-when-a-level-is-loaded-c/448161/4 "2019-05-01T14:57:44Z")

</div>

the begin play will be triggered at the beginning of the game ( so when all persistent levels are loaded )

for the second part, it’s related to each sublevels, you would need a list of sublevels name to iterate on that and register event for all sublevels
