# Dynamic data in components (Color)

**URL:** <https://forums.unrealengine.com/t/dynamic-data-in-components-color/393828>\
**Category:** Rendering\
**Tags:** random-numbers, unreal-engine, UE4, question, CPP\
**Created:** [May 17, 2017, 11:02am UTC](https://forums.unrealengine.com/t/dynamic-data-in-components-color/393828 "2017-05-17T11:02:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7c9994f6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7c9994f6](https://forums.unrealengine.com/u/anonymous_user_7c9994f6)\
**Post date:** [May 17, 2017, 11:02am UTC](https://forums.unrealengine.com/t/dynamic-data-in-components-color/393828/1 "2017-05-17T11:02:42Z")

</div>

Hello everyone

At first, im new in C++ and Unreal.

I have a code which it changes de color randomly of a mesh. I know that i can solve it using FLinearColor::MakeRandomColor.

This code runs in a ‘onHit’ function.

My question is: _ **¿Why i cant use C++ functions like rand?** _

In a future, I’ll connect with data transfered by a script made in Python. The data will contain the color of my materials. I think I’ll get the same problem because is dynamic data.

Thanks so much,

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [May 18, 2017, 8:08pm UTC](https://forums.unrealengine.com/t/dynamic-data-in-components-color/393828/2 "2017-05-18T20:08:16Z")

</div>

Make sure you create a UMaterialInstanceDynamic first (in Begin Play as Example) and assign it to the Mesh. After that you can set Material Parameters as you like. FLinearColor::MakeRandomColor() or FColor::MakeRandomColor() work as expected.

Here some Docs about Dynamic Materials

> **[Instanced Materials](https://docs.unrealengine.com/4.27/en-US/RenderingAndGraphics/Materials/MaterialInstances/)**
>
> Hierarchical material relationships that allow modification of properties to alter behavior and appearance of child materials without shader recompilation.
