NEED HELP: Clamping Base Class' SpringArmComponent's TargetArmLength

I tried coding the clamps into the Base Class of Spring Arm Component’s Target Arm Length.


So far, I set the clamps and tried with this in .cpp, but the Target Arm Length completely ignores the set clamps in my subclass. Where’s the problem?



To clarify: CndPlayerSpringArmComponent is my custom name of the subclass.

I managed to somehow do something similar with Camera Component, but I can’t seem to do the same with SpringArmComponent TargetArmLength.

hello @GraczCourier

you want to limit the range of the Target Arm Length variable, right?

That’s what I’m trying to do. Limit the range of TargetArmLength to these adjustable Clamps, so its value won’t go beyond those clamps.

@GraczCourier

You were on the right track, but the entry TargetArmLength = FMath::Clamp(TargetArmLength, Min, Max); limits the value only once and assigns it to a variable.

In order for the value of a variable to be limited every time we change it, we need to catch the moment the variable changes, here’s how we’ll do it:

In the unreal engine, almost every class of various kinds of objects has a PostEditChangeProperty() method; it is called every time any variable of the object changes. By inheriting a class from USpringArmComponent you also get access to this method in your class, you need to override this method by writing it in your class.
By default, this method takes the data structure of the variable that initiated its call, and we can get its name and compare it with the name of the variable we need - if they match, then the desired variable has changed and we can limit its value:


1 Like