# Setup Components attribute through cpp

**URL:** <https://forums.unrealengine.com/t/setup-components-attribute-through-cpp/563805>\
**Category:** C++\
**Tags:** unreal-engine, UE5-0, Components, CPP, question\
**Created:** [May 23, 2022, 1:14am UTC](https://forums.unrealengine.com/t/setup-components-attribute-through-cpp/563805 "2022-05-23T01:14:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mellowperator](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mellowperator](https://forums.unrealengine.com/u/Mellowperator)\
**Post date:** [May 23, 2022, 1:14am UTC](https://forums.unrealengine.com/t/setup-components-attribute-through-cpp/563805/1 "2022-05-23T01:14:26Z")

</div>

I want to change variables automatically for my character health and Mana.

I created a new C++ component who hold the health pool, damage reduction and damage function. but inside my parent character class I put the health, damage reduction. because I have more than one archetype.

AMyCharacter::AMyCharacter(){  
…  
HealthComp = CreateDefaultSubobject(TEXT(“HealthComp”));  
HP = 120;  
DamageReduction = .15f;  
SP = 100;  
HealthComp-\>HealthPool = this-\>HP;  
HealthComp-\>DamageReduction = this-\>DamageReduction;  
}

but when I start my game, the character only have my default value of HP = 100 and Damage reduction = .10f

I don’t understand why it don’t get the values I gave it. I don’t want to use blueprint because it’s not scalable as C++. and I will have more components that need to get information from the parent class.

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [May 23, 2022, 2:06am UTC](https://forums.unrealengine.com/t/setup-components-attribute-through-cpp/563805/2 "2022-05-23T02:06:25Z")

</div>

variables modified in the constructor can be overriden by blueprints, this can easily happen if the variable is a UPROPERTY.

You can also set the vars on BeginPlay() , then they will override anything set on the editor panel or in the constructor.
