# ClampMin and ClampMax meta for specific UFUNCTION arguments?

**URL:** <https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146>\
**Category:** C++\
**Tags:** parameters, unreal-engine, clamp, CPP, Blueprint, question\
**Created:** [January 3, 2023, 12:54pm UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146 "2023-01-03T12:54:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bdc_patrick/32/1104221_2.png) [@BDC\_Patrick](https://forums.unrealengine.com/u/BDC_Patrick)\
**Post date:** [January 3, 2023, 12:54pm UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/1 "2023-01-03T12:54:49Z")

</div>

hi there…

I, f.e. got his function:

```auto
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category="Testing")
void DoThings(int A, int B, int C, FVector3d& ReturnPoint);

```

I now want to have B, and only B, being clamped between 5 and 50…  
Since there is no way to tell the UFUNCTION, which argument the meta should affect, and UPROPERTY won’t help either, I searched a while through Google, stackoverflow and diverse UE coding pages…

I found UPARAM… and tried it…  
This is the result:

```auto
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category="Testing")
void DoThings(int A, UPARAM(meta=(ClampMin="5", ClampMax="50"))int B, int C, FVector3d& ReturnPoint);

```

And it is doing absolutely… nothing… it just won’t clamp the value of B (in the BP Node) between 5 and 50… I can put -8498 or 999 or anything else inside… and it won’t get clamped…

How can one clamp a specific argument?

---

<div class="post-metadata">

**Author:** ![FishBone0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FishBone0](https://forums.unrealengine.com/u/FishBone0)\
**Post date:** [January 3, 2023, 1:18pm UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/2 "2023-01-03T13:18:55Z")

</div>

I don’t think that would be possible  
You can use the clamp on a uproperty and use that, or you’d have to clamp the value inside the function.

---

<div class="post-metadata">

**Author:** ![Megatron.THX](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/megatron.thx/32/707762_2.png) [@Megatron.THX](https://forums.unrealengine.com/u/Megatron.THX)\
**Post date:** [January 3, 2023, 11:51pm UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/3 "2023-01-03T23:51:42Z")

</div>

Hi @BDC_Patrick

Like @FishBone0 said you can clamp inside the function:

```auto
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category="Testing")
void DoThings(int A, int B, int C, FVector3d& ReturnPoint);
...
void AYourClase::DoThings(int A, int B, int C, FVector3d& ReturnPoint)
{
A = FMath::Clamp(A, 5.f, 50.f);
...
}

```

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [January 4, 2023, 1:05am UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/4 "2023-01-04T01:05:49Z")

</div>

In addition to clamping in the function itself, you can also implement OnPropertyChanged and force it to remain clamped when set… that way you don’t have it appearing to be 0 in editor, but it being clamped to 5 in runtime, or whatever.

---

<div class="post-metadata">

**Author:** ![FishBone0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FishBone0](https://forums.unrealengine.com/u/FishBone0)\
**Post date:** [January 4, 2023, 10:46am UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/5 "2023-01-04T10:46:03Z")

</div>

No need to use OnPropertyChanged, as the property itself can be clamped with `meta=(ClampMin="5", ClampMax="50")` in the UPROPERTY specifier

---

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bdc_patrick/32/1104221_2.png) [@BDC\_Patrick](https://forums.unrealengine.com/u/BDC_Patrick)\
**Post date:** [January 4, 2023, 2:59pm UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/6 "2023-01-04T14:59:07Z")

</div>

which is not eorking for a UFUNTION… since the meta is not knowing which argument is meant to be clamped…

would be nice if epic implements such a thing… so we have a MinMax Slider in the Node

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [January 4, 2023, 3:08pm UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/7 "2023-01-04T15:08:46Z")

</div>

Seems like a bit of a case of over-engineering.

 ![1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/4/9/449ce17c36dd44f038bae3ed33858c60e92685f2.jpeg)  
 ![2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/7/e2705025c05dd1c9eb732eec5860f443d032b356.jpeg)

It’s a function. You need to pass in it’s limits, otherwise why not just bake them inside the function as local variables and clamp the value?  
If you want cleaner inputs then you can also go for a FVector2d to pass in min and max in the same line.

---

<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:** [January 4, 2023, 4:19pm UTC](https://forums.unrealengine.com/t/clampmin-and-clampmax-meta-for-specific-ufunction-arguments/741146/8 "2023-01-04T16:19:05Z")

</div>

The clamp meta is only useful for property editors when designing / configuring from the editor panel. That meta does not even exist without the editor. They can not be used for proper validation and will not automatically clamp a value when you set a property from code. The easiest way to set up value validation is to make your properties private and validate through public setter methods. In the case of functions just validate the arguments within the function and print a warning when something is not what you expect, or clamp a value if that is what you wish, or assert if an input may never be a wrong value.
