How change "Float Curve" key value?

Hello.

Is it possible to change the Float Curve key value using Blueprint?
If not, is it even possible to programmatically change the value of the Float Curve key?

I found a solution. I want to share it with you.
To do this, you need to create a custom node using C++.
If you do not use C++ in your project, then you need to download Visual Studio. You can read the instructions here: Setting Up Visual Studio Development Environment For C++ Projects In Unreal Engine | Unreal Engine 5.1 Documentation | Epic Developer Community
After installation:

  1. Open your project - Tools - New C++ class

  2. All classes - BlueprintFunctionLibrary - Next

  3. Set the name of your library - Create Class

  4. If VS does not open then go to your project folder and there should be a file [YourProjectName].sln. Open it.
    In Solution Explorer: Game - [YourProjectName] - Source - [YourProjectName] - Open [YourLibraryName].cpp and [YourLibraryName].h
    If VS opens then [YourLibraryName].cpp and [YourLibraryName].h will be open.

  5. In [YourLibraryName].h paste code:

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Curves/CurveFloat.h"
#include "[YourLibraryName].generated.h" /*Replace [YourLibraryName] with your library name*/

UCLASS()
class [YourProjectName]_API U[YourLibraryName] : public UBlueprintFunctionLibrary /*Replace [YourProjectName] with your project name in capital letters. Replace [YourLibraryName] with your library name*/
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, Category = "My Custom Function")
	static void SetFloatCurveKeyValue(UCurveFloat* Curve, float Time, float NewValue);

};
  1. In [YourLibraryName].cpp paste code:
#include "[YourLibraryName].h" /*Replace [YourLibraryName] with your library name*/

void U[YourLibraryName]::SetFloatCurveKeyValue(UCurveFloat* Curve, float Time, float NewValue) /*Replace [YourLibraryName] with your library name*/
{
    if (!Curve) return;

    // Find a key that matches a given time
    FKeyHandle KeyHandle = Curve->FloatCurve.FindKey(Time);

    // If the key is not found, add a new key
    if (KeyHandle == FKeyHandle::Invalid())
    {
        Curve->FloatCurve.AddKey(Time, NewValue);
    }
    else
    {
        //Changing the value of an existing key
        Curve->FloatCurve.UpdateOrAddKey(Time, NewValue);
    }
}
  1. Save all
  2. In Solution Explorer: Game - [YourProjectName] - Right click - Build
  3. If everything went well, then you can find your node in the blueprint:
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.