# How can I add a random float for a Material Instance Constant?

**URL:** <https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912>\
**Category:** Rendering\
**Tags:** time, random, unreal-engine, Blueprint, question\
**Created:** [June 27, 2014, 9:00pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912 "2014-06-27T21:00:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MongooseJV](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MongooseJV](https://forums.unrealengine.com/u/MongooseJV)\
**Post date:** [June 27, 2014, 9:00pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/1 "2014-06-27T21:00:19Z")

</div>

I have a constant material that I want to use for the sake of performance. This will be a mobile app so I don’t want to spawn a dynamic material for every tile. However, I want my tiles to pulse like a star would. It is easy enough to add a time element and cosine it doing a lerp between the dim/bright colors that make up the pulse. My problem is they all pulse exactly the same. I wanted to add a random float value to the time parameter so they all pulse at different times. Is there a way to achieve this without having to create a dynamic material instance for every tile??

Thanks so much!

- Jeff

---

<div class="post-metadata">

**Author:** ![Jacky](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jacky/32/918690_2.png) [@Jacky](https://forums.unrealengine.com/u/Jacky)\
**Post date:** [June 27, 2014, 9:05pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/2 "2014-06-27T21:05:28Z")

</div>

You can turn that time multiplier into a Collection Parameter, create a Material Parameter Collection in the content browser and use it in the blueprint to change the parameter for all instances.

---

<div class="post-metadata">

**Author:** ![MongooseJV](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MongooseJV](https://forums.unrealengine.com/u/MongooseJV)\
**Post date:** [June 27, 2014, 9:44pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/3 "2014-06-27T21:44:04Z")

</div>

I’m trying to find documentation on this. I’ve added the material collection in the browser and dragged/dropped it onto the material so I can access the “RandomOffset” value that I created. Now I’m trying to figure out how I can send this value via Blueprint. I’m not sure you can do this for a material instance constant… Wouldn’t there only be one value per constant instance rather than per spawned actor I’m generating??

---

<div class="post-metadata">

**Author:** ![MongooseJV](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MongooseJV](https://forums.unrealengine.com/u/MongooseJV)\
**Post date:** [June 27, 2014, 9:54pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/4 "2014-06-27T21:54:29Z")

</div>

I found the documentation and I don’t think you understand what I’m trying to do. I have 50+ spawned actors all using a single material (constant). However, I want each actor to be responsible for updating the material with a different random value at the start of the game.

I know you can do this if you created 50 dynamic material instances but I feel like that is a waste… The Material Parameter Collection is used to pass in global values that all materials may want to use such as Player Location, etc.

---

<div class="post-metadata">

**Author:** ![ActualZak](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ActualZak](https://forums.unrealengine.com/u/ActualZak)\
**Post date:** [June 27, 2014, 10:22pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/5 "2014-06-27T22:22:28Z")

</div>

You could incorporate the ObjectPositionWS node into your material and use that as a means to create an offset. It outputs the world space coordinate for your object’s location. You could do something crazy like average R, G, and B together and use the output of that to drive an offset. I’d probably clamp it in some way to reach your goals.

But I just tested this network on some objects placed around my level and they all flicker differently.

 ![9237-randomflickergraph.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/f/c/dfc80288d5a223ad4abf6294e1f2c9a733a3e8d7.png)

---

<div class="post-metadata">

**Author:** ![ActualZak](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ActualZak](https://forums.unrealengine.com/u/ActualZak)\
**Post date:** [June 27, 2014, 10:23pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/6 "2014-06-27T22:23:40Z")

</div>

Oh, and I didn’t need a MatInst Constant for this. Just FYI. You could, though. Just keep in mind that when you want different instances to have different values of ANYTHING, you need a dynamic material instance.

---

<div class="post-metadata">

**Author:** ![MongooseJV](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MongooseJV](https://forums.unrealengine.com/u/MongooseJV)\
**Post date:** [June 27, 2014, 11:35pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/7 "2014-06-27T23:35:11Z")

</div>

I guess I’ll have to make instances then. My tiles are aligned in a 2x2 grid so it won’t appear too random using the position. I also need to figure out if it will be a performance problem for mobile devices to have an instance per tile. Thanks!

---

<div class="post-metadata">

**Author:** ![RVillani](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rvillani/32/1194572_2.png) [@RVillani](https://forums.unrealengine.com/u/RVillani)\
**Post date:** [February 3, 2017, 7:15pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/8 "2017-02-03T19:15:13Z")

</div>

For those coming here again (like me), if you’re using InstancedStaticMesh or HISM, there’s a node in the materials called **PerInstanceRandom**. It outputs a random float for each instance that doesn’t change along that instance’s lifespan. That way you can have random stuff unique for each instance, independent of their location.

---

<div class="post-metadata">

**Author:** ![TorQueMoD](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/torquemod/32/710746_2.png) [@TorQueMoD](https://forums.unrealengine.com/u/TorQueMoD)\
**Post date:** [July 31, 2023, 6:37pm UTC](https://forums.unrealengine.com/t/how-can-i-add-a-random-float-for-a-material-instance-constant/286912/9 "2023-07-31T18:37:02Z")

</div>

I get an error using the Object Position in my Light Function. It says [SM5] /Engine/Generated/Material.ush(2136,21-54): error X3004: undeclared identifier ‘GetObjectWorldPosition’
