How to remap values in Blueprints

Hey all,

It there an action in blueprints that allows to scale or remap values from one range to another range? For example scale values 0-1 to 0-127.

I’m used to the scale objects in Max: scale Reference

Thanks.

You can’t remap values as values are not “mapped” to begin with,… or rether it mapped by fact it being specific type.

Integer in blueprint is a type in memory which is signed 32-bit (4-bytes) number which can have 4294967296 different states, signed means 1 bit is deicated to store sign of number, either is negative or possitive number, removing one bit means only half of states can be used for both directions to 2147483647. In C++ this type is int32

Blueprint supports also other integer type called “Byte” which is unsigned 8-bit (1-byte) number, which can have 256 different states, unsigned means all 8 bits are used for number and can’t have negative values, so it can store numbers from 0 to 255. In C++ this type is called uint8,

C++ supports other integer types 8,16,32 and 64 bits, signed and unsigned, but UE4 reflection system and as result blueprints only support those 2. So you are forced to store in either of those 2 and there no way around it, if you want to save 3 bytes of memory for each variable use Byte on varables that won’t be bigger then 255.

Float which is type that can hold fraction of numbers is a lot more complex (to tell the truth i didn’t stud y that so i throw wiki :p) but it also got it own range: Single-precision floating-point format - Wikipedia

Other then that you can use some form of varable control, some kind of gateway that validates inputed data and varable it self. Most common method used in programming is use of Get/Set function where you set variable using a function instead of dirrecly setting varable, function checks if input is valid if it’s not he does some kind of correction, for example max value 16 and input is 18 function set variable to max 16. You can hold varable as private varable so externally it can be only set and get via function, forceing external code to go thru this validation gateway to do anything with it. There set of Math nodes that help you with that like Min (return smallest inputed number, regardless of name it let you set maximum range of variable), Max (return biggest inputted number, so let you set minimum number), Float has a lot more useful function like Lerp:

or Clamp:

Bigger problem is Details and Defaults tab which won’t block you to input any varable, here you will need to validate by other means, like check variables on Begin Play. In C++ UE4 let you set Max and Min value in meta specfiers in UPROPERTY, blocking property input in Details and Defaults, at leats i think maybe i missing something maybe there is way to do that in Blueprint alone, check variable settings

to convert a number from the range A to B, into the range X to Y, you would

subtract A, 
 divide by (B - A), 
 multiply by (Y - X), 
 then Add X.

in summary:
( ( i - A ) / ( B - A ) ) * (Y - X) + X

there is also a node called MapRangeClamped, that does this automatically,

but if you just need to transform a number between 0 and 1, to a number between 0 and 127, and you want to do it most efficiently, you can just multiply the number by 127.

4 Likes

Yes, there is a blueprint node named “map to” that does exactly what you want. There is an example of it within the BP_SkySphere blueprint.

Cheers

1 Like

This is exactly what I was looking for! Thank you.

I’d like to add that if you are using 0, 1 for the input range, you can simply skip to step 3, as step 1 and 2 do not change the input value for this range. I’m doing this in the material editor, so I don’t have access to MapRangeClamped.

So i think that more easy way to remap is using [Lerp] function - you can attach slider to Alpha (with settings from 0 to1 or any other values) and set [A] and [B] parameters in [Lerp].

There is a node that does this already, it maps the range and also uses lerp. The Unclamped version just maps the range.

126511-uefriend.jpg

4 Likes

**In C++,The Function Exists in FMath **
…Engine/Source/Runtime/Core/Public/Math/UnrealMathUtility.h

about line 606

/** Transform the given Value relative to the input range to the Output Range. */
static FORCEINLINE float GetMappedRangeValueUnclamped(const FVector2D& InputRange, const FVector2D& OutputRange, const float Value)
{
		return GetRangeValue(OutputRange, GetRangePct(InputRange, Value));
}

Map Range Clamped

RemapValueRange in the material blueprint,
Map Range Clamped / UnClamped in the blueprint.
The map behind it please sees other people. :wink: