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?
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:
Open your project - Tools - New C++ class
All classes - BlueprintFunctionLibrary - Next
Set the name of your library - Create Class
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.
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);
};
#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);
}
}
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.