How to desync sine waves?

Hi! I have a material with a sine way I use to make my assets appear to float up and down.

However, as this wave is multiplied by time, they are all perfectly in sync with eachother.

How would you randomize the sine so that the instances aren’t synchronized?
I’ve considered using something like the world position of the actor as a seed, but it’s a pawn that moves around. I don’t want it’s movement to affect the floaty motion.

Using a material parameter and setting it from C++ or Blueprint is the first thing that comes to mind. The parameter can drive wave offsets and multiplication of the ax + b type. Create a random value for the offset in the pawn and pass it to the material.

Some relevant functions are:

UMaterialInstanceDynamic::SetScalarParameterValue
UMaterialInstanceDynamic::SetVectorParameterValue

UMeshComponent::SetScalarParameterValueOnMaterials
UMeshComponent::SetVectorParameterValueOnMaterials

and their Blueprint equivalents.

1 Like

Thanks! That’s not a bad idea. I’m already setting another parameter in these materials through code, so adding another value should be easy.

I just add a random value to the time input, right?

That should work, yes.

1 Like

Thanks! That worked like a charm.

If it’s using isntancing you can just call a perinstancerandom.
And by default you probably are?