# Update Reflection Capture on Runtime

**URL:** <https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779>\
**Category:** Architectural and Design Visualization\
**Tags:** unreal-engine\
**Created:** [April 11, 2016, 7:55am UTC](https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779 "2016-04-11T07:55:08Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![bayanm9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bayanm9](https://forums.unrealengine.com/u/bayanm9)\
**Post date:** [March 21, 2019, 5:56pm UTC](https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779/22 "2019-03-21T17:56:14Z")

</div>

> [@TobiGroth](#):
>
> So, I have build something…
> 
> **Pros**
> 
> - It updates the reflection captures
> 
> **Cons**
> 
> - It does \*\*NOT \*\*work in the packaged game! (_because of this check in ReflectEnvironmentCapture.cpp (line 1439))_
> 
> ```auto
> 
> if (FPlatformProperties::RequiresCookedData())
> {
> UE_LOG(LogEngine, Warning, TEXT("No built data for %s, skipping generation in cooked build."), *CaptureComponent->GetPathName());
> return;
> }
> 
> ```
> 
> - It’s hacky
> - short hickup _(which was to be expected)_
> 
> ```auto
> 
> for (ULevel* Level : World->GetLevels())
> {
> if (Level->bIsVisible)
> {
> if (Level->MapBuildData)
> {
> Level->MapBuildData->InvalidateReflectionCaptures(nullptr);
> }
> }
> }
> 
> FScene* Scene = (FScene*) World->Scene;
> if (Scene)
> {
> TArray<UReflectionCaptureComponent*> ReflectionCapturesToUpdate;
> for (TObjectIterator<UReflectionCaptureComponent> Itr; Itr; ++Itr)
> {
> if (IsValid(*Itr))
> {
> ReflectionCapturesToUpdate.Add(*Itr);
> }
> }
> 
> bool bOldIsEditorScene = Scene->bIsEditorScene;
> Scene->bIsEditorScene = true;
> World->Scene->AllocateReflectionCaptures(ReflectionCapturesToUpdate, TEXT("UpdateReflectionRuntime"), false);
> Scene->bIsEditorScene = bOldIsEditorScene;
> }
> else
> {
> // IT DIDN'T WORK
> }
> 
> ```
> 
> Using UE4.21 btw
> 
> If anyone can figure out how to get it to work in the packaged game without editing engine source code I’d be very grateful!

Can you please share where do you enter this code?  
are you replacing the code after line 1439?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d0ee7ef0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d0ee7ef0](https://forums.unrealengine.com/u/anonymous_user_d0ee7ef0)\
**Post date:** [March 25, 2019, 10:40am UTC](https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779/23 "2019-03-25T10:40:27Z")

</div>

> [@bayanm9](#):
>
> Can you please share where do you enter this code?  
> are you replacing the code after line 1439?

You just place the big code block in any actor you like. Trigger it with a key or a timer ever 5 seconds to test maybe.

---

<div class="post-metadata">

**Author:** ![frezer748](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@frezer748](https://forums.unrealengine.com/u/frezer748)\
**Post date:** [May 9, 2019, 10:35pm UTC](https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779/24 "2019-05-09T22:35:09Z")

</div>

I am also looking for a similiar technique like the “Environment Probe” in CryEngine. Because there you could have multiple level/layers with different times of day and it automatically updates the reflection capture when switching the lighting conditions. Currently I always have to rebuild reflection capture when I unhide a certain level with another time of day(Directional light in it) to get a proper reflection in the scene. Or is there a different way to achieve this in UE4?

---

<div class="post-metadata">

**Author:** ![S-Dot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/s-dot/32/1194599_2.png) [@S-Dot](https://forums.unrealengine.com/u/S-Dot)\
**Post date:** [May 9, 2019, 11:00pm UTC](https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779/25 "2019-05-09T23:00:43Z")

</div>

> [@frezer748](#):
>
> I am also looking for a similiar technique like the “Environment Probe” in CryEngine. Because there you could have multiple level/layers with different times of day and it automatically updates the reflection capture when switching the lighting conditions. Currently I always have to rebuild reflection capture when I unhide a certain level with another time of day(Directional light in it) to get a proper reflection in the scene. Or is there a different way to achieve this in UE4?

Are you using lighting scenarios?

> **[Precomputed Lighting Scenarios](https://docs.unrealengine.com/5.3/en-US/using-precomputed-lighting-scenarios-in-unreal-engine/)**
>
> An overview of using multiple lighting setups for a single scene.

---

<div class="post-metadata">

**Author:** ![Dredfort](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dredfort](https://forums.unrealengine.com/u/Dredfort)\
**Post date:** [October 1, 2019, 9:45am UTC](https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779/26 "2019-10-01T09:45:21Z")

</div>

In my case

> [@](#):
>
> // Rebuild reflection captures.  
> if (GEditor)  
> {  
> GEditor-\>BuildReflectionCaptures();  
> }

works fine.

[Previous page](https://forums.unrealengine.com/t/update-reflection-capture-on-runtime/60779.md?page=1)
