How to limit a function input parameter setting min/max value without a widget?

Hi Everyone, I’m trying to make an Editor Scripting Utility in C++ and I was wondering if I could limit the input of the function, in this case for example I need the parameter to always be > 0:

	UFUNCTION(CallInEditor)
	void DuplicateAsset(uint32 NumberOfDuplicates = 1, bool bSave = true);

I could use “clamp” or a simple “if” to check if the number is less than one and change it to one, but that would only affect the result and not “what the user sees”

	if (NumberOfDuplicates < 1)
	{
		NumberOfDuplicates = 1;
	}

I also noticed that the value is automatically limited to positive numbers, so in this case I’d just need to exclude the 0, but I’m curious to know how to allow negative numbers in the input:

image

Thank you in advance!

Hi Ares9323,

I haven’t tried it in this way, but this UProperty meta tag may work: “meta=(ClampMin=“0”,ClampMax=“100.0”, UIMin=“0”,UIMax=“100.0”)”

3 Likes

Thanks for your answer, I’ve tried to use the meta tag for UPROPERTY (only ClampMin to be honest) but it looks like it’s getting ignored (and it makes sense, because if you have more than one integer variable the program doesn’t know which variable to limit, and that meta is not present in the “Function Metadata Specifiers” of the documentation).

Maybe there’s a way to specify meta tags for each parameter but I haven’t been able to find it!

1 Like

Yeah worth a try anyway. What about rather than passing them in as method parameters you just have them as UPROPERTIES that the CallInEditor method references?

1 Like

That’s an option that I considered, but I have many functions that have the same parameter name and accept different values, so that doesn’t apply very well.

I’m probably going to use a widget and limit the value from there…

1 Like

There’s not a way to prevent a function from being called with a parameter that is out of bounds, clamp parameters only work on editor values for properties.

So, if you have a property setup that defines the value to call the function with, then you can clamp the min/max on the property. But you can’t clamp the function call itself.

1 Like

Thanks for your answer, do you know why is it already limited to positive numbers? Shouldn’t uint32 also allow negative numbers?

The “u” part of “uint32” means “unsigned” so no :slight_smile: int32 is what you’re looking for

1 Like

I’ve always used int32, this is literally the first time I used “uint32” because I was following a tutorial, I thought that the “U” was just something like the prefix with “UObject”, I would have never Imagined that it meant “unsigned” :sweat_smile::rofl:.

Thank you so much again, it’s kinda strange to discover this after a year and a half of using Unreal

1 Like