# UObject's Instanced value reset to C++ default value on Play?

**URL:** <https://forums.unrealengine.com/t/uobjects-instanced-value-reset-to-c-default-value-on-play/450629>\
**Category:** Community & Industry Discussion\
**Tags:** UProperty, uobject, serialization, unreal-engine, Scripting, Components, question\
**Created:** [June 13, 2019, 7:32pm UTC](https://forums.unrealengine.com/t/uobjects-instanced-value-reset-to-c-default-value-on-play/450629 "2019-06-13T19:32:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albatros155](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Albatros155](https://forums.unrealengine.com/u/Albatros155)\
**Post date:** [June 13, 2019, 7:32pm UTC](https://forums.unrealengine.com/t/uobjects-instanced-value-reset-to-c-default-value-on-play/450629/1 "2019-06-13T19:32:33Z")

</div>

Hello everyone,

I’m currently implementing an “Emotion Component” (that inherit from an Actor Component) that have a list of “EmotionGauge” (that inherit from a UObject and FTickableGameObject).

Unfortunately, I’m having a weird problem when I click on the “Play” in the Editor:  
Some of the value in the EmotionGauge are reset to their default C++ values, and do not take the BP Value into account.

I’ll try to be clear as possible:  
So, I placed a character in my current map, and I’m able to see the default value from C++ correctly:

 ![279695-emotion-problem01.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/6/e660a2f4466656320b901581c5537c2f85f402f9.png)

So now I decide to change these default values in the Character BP:

 ![279696-emotion-problem02-bp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/a/6/aa6fbc38ea2b725c2b6d9002b3d07c4205b557b7.png)

If I go back to my character in the map I can see that it show the BP value and consider it as the default one:

 ![279697-emotion-problem02.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/1/b216a2134a223593fd8b274f4d29536159466de2.png)

Now, when I press play, it will get the value from the C++ file, and not from the BP:

 ![279698-emotion-problem03.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/8/b/38bec71174ab28dc2a5ff677180afb220607a20f.png)

**Note that if I don’t modify the default value in the BP but directly in the instanced character in the map, it takes correctly the value and don’t reset it to C++ value**

For more info, you can see the implementation below:

So the Emotion Component is an actor component that contains a list of “EmotionGauge”, here is the .h:

```
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CROWDBEHAVIOR_API UEmotionComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UEmotionComponent();

// ........................

protected:

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Emotion", Instanced)
    TArray<UEmotionGauge*> EmotionGaugeList;

};

```

So, now in the constructor, I’m filling the Array by creating several “EmotionGauge”, here’s the .cpp:

```
// Sets default values for this component's properties
UEmotionComponent::UEmotionComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

    for (int i = 0; i < (int)EEmotionCategory::COUNT; ++i)
    {
        EEmotionCategory EmotionCategory = (EEmotionCategory)i;
        FString EmotionGaugeName = EnumToString("EEmotionCategory", EmotionCategory) + "Gauge";

        UEmotionGauge* NewEmotionGauge = CreateDefaultSubobject<UEmotionGauge>(FName(*EmotionGaugeName));
        EmotionGaugeList.Add(NewEmotionGauge);
    }
}

```

So before pressing play, in the BP everything is working fine, the array is filled correctly and for each element I can modify the value contained in the “EmotionGauge”, here is EmotionGauge.h:

```
UCLASS(BlueprintType)
class CROWDBEHAVIOR_API UEmotionGauge : public UObject, public FTickableGameObject
{

    GENERATED_BODY()

protected:
    UPROPERTY(EditAnywhere, Category = "Gauge Cooldown")
    bool bDoesValueChangeOverTime = false;
    // In Value/Sec. Represent the speed at which the gauge will tends to the wanted value.
    UPROPERTY(EditAnywhere, Category = "Gauge Cooldown", meta = (EditCondition = "bDoesValueChangeOverTime", ClampMin="0.0"))
    float ModifyingRate = 1.f;
    // Represent the value the gauge will tends to over time.
    UPROPERTY(EditAnywhere, Category = "Gauge Cooldown", meta = (EditCondition = "bDoesValueChangeOverTime"))
    float TargetValueForCooldown = 0.f;

    UPROPERTY(EditAnywhere, Category = "Gauge Cooldown", meta = (EditCondition = "bDoesValueChangeOverTime", ClampMin = "0.0"))
    float DelayForTriggeringCooldown = 5.f;

private:
    UPROPERTY(VisibleAnywhere, Category = "Gauge Cooldown")
    float CooldownRemainingDelay = 1.f;

};

```

Does anyone know what’s going on?

Thank you

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2ab97073](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2ab97073](https://forums.unrealengine.com/u/anonymous_user_2ab97073)\
**Post date:** [January 5, 2021, 1:31pm UTC](https://forums.unrealengine.com/t/uobjects-instanced-value-reset-to-c-default-value-on-play/450629/2 "2021-01-05T13:31:27Z")

</div>

Same issue for me, and I saw a lot of threads created since 2015 with the same kind of issue, but I’ve never saw an answer to this problem …

---

<div class="post-metadata">

**Author:** ![ThD\_ManiaC](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/thd_maniac/32/1194665_2.png) [@ThD\_ManiaC](https://forums.unrealengine.com/u/ThD_ManiaC)\
**Post date:** [January 23, 2021, 10:36am UTC](https://forums.unrealengine.com/t/uobjects-instanced-value-reset-to-c-default-value-on-play/450629/3 "2021-01-23T10:36:41Z")

</div>

You may check out if any additional Macro in the UCLASS( … ) definition in your EmotionGauge.h or the UPROPERTY( … ) in EmotionComponent.h does help you out on this.
