# Incorrect state when buffer fills mid-episode. 

**URL:** <https://forums.unrealengine.com/t/incorrect-state-when-buffer-fills-mid-episode/2835458>\
**Category:** AI\
**Tags:** Reinforcement-Learning, unreal-engine, Learning-Agents, bug-report\
**Created:** [September 29, 2026, 7:39pm UTC](https://forums.unrealengine.com/t/incorrect-state-when-buffer-fills-mid-episode/2835458 "2026-09-29T19:39:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MannyVindiola](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MannyVindiola](https://forums.unrealengine.com/u/MannyVindiola)\
**Post date:** [September 29, 2026, 7:39pm UTC](https://forums.unrealengine.com/t/incorrect-state-when-buffer-fills-mid-episode/2835458/1 "2026-09-29T19:39:57Z")

</div>

Hello,

I think there is an issue with filling the replay buffer when an episode is longer than the remaining steps.

If you look here:

[https://github.com/EpicGames/UnrealEngine/blob/396c9f059903aed5fec78ecd3d437a40c6415368/Engine/Plugins/Experimental/LearningCore/Source/LearningTraining/Private/LearningExperience.cpp#L473-L481](https://github.com/EpicGames/UnrealEngine/blob/396c9f059903aed5fec78ecd3d437a40c6415368/Engine/Plugins/Experimental/LearningCore/Source/LearningTraining/Private/LearningExperience.cpp#L473-L481)

and here:

[https://github.com/EpicGames/UnrealEngine/blob/396c9f059903aed5fec78ecd3d437a40c6415368/Engine/Plugins/Experimental/LearningCore/Source/LearningTraining/Private/LearningExperience.cpp#L497-L505](https://github.com/EpicGames/UnrealEngine/blob/396c9f059903aed5fec78ecd3d437a40c6415368/Engine/Plugins/Experimental/LearningCore/Source/LearningTraining/Private/LearningExperience.cpp#L497-L505)

`InEpisodeFinalObservations[Index][InstanceIdx])` and `InEpisodeFinalMemoryStates[Index][InstanceIdx])` are the final states of the episode but because the buffer could not fit an entire episode they are not the correct values to fill in.

For example if the episode was 100 steps long but PartialStepNum is 10. This will take the final values at step 100 giving you values from steps [0, 1 , 2 , 3 , 4 , 5, 6, 7, 8, 100]. This is particularly bad for learning because the episode is marked as truncated so it will bootstrap the value estimate using the critic with the incorrect final observation and affect all the returns for that episode. Advantages will also be computed from the wrong final observation.

Luckily this can only affect one value per gather. In my training runs 0.4%-0.8% of each gather carried an incorrect advantage and critic return label.

The correct copies are:  
Array::Copy(  
EpisodeFinalObservations[Index][EpisodeNum],  
EpisodeBuffer.ObservationArrays[Index][InstanceIdx][PartialStepNum]);

Array::Copy(  
EpisodeFinalMemoryStates[Index][EpisodeNum],  
EpisodeBuffer.MemoryStateArrays[Index][InstanceIdx][PartialStepNum]);

---

<div class="post-metadata">

**Author:** ![MannyVindiola](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MannyVindiola](https://forums.unrealengine.com/u/MannyVindiola)\
**Post date:** [September 30, 2026, 1:02am UTC](https://forums.unrealengine.com/t/incorrect-state-when-buffer-fills-mid-episode/2835458/2 "2026-09-30T01:02:34Z")

</div>

Oh I forgot to mention this same issue can happen on the python side when trim\_episode\_end \> 0. I set that value to 0 so it does not apply to my scenarios.

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [September 30, 2026, 6:14pm UTC](https://forums.unrealengine.com/t/incorrect-state-when-buffer-fills-mid-episode/2835458/3 "2026-09-30T18:14:20Z")

</div>

Thanks again, will take a look!

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [October 22, 2026, 3:40pm UTC](https://forums.unrealengine.com/t/incorrect-state-when-buffer-fills-mid-episode/2835458/4 "2026-10-22T15:40:30Z")

</div>

A fix for this has been submitted on Main. Thanks for the post!
