Download

Error when add UCurveFloat

Hello,
i have a custom character’s class write in c++ where i add a UCurveFloat. I want to create a timeline, but not function.

This is my PlayerCharacter.h




			UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Combat")
				class UCurveFloat* CombatModeCurve;

			FTimeline TimeLine;

			UFUNCTION()
				void EffectProgress(float Value);



This is my PlayerCharacter.cpp




APlayerCharacter::APlayerCharacter()
{
	TimeLine = FTimeline{};
	FOnTimelineFloat progressFunction;
	progressFunction.BindUFunction(this, "EffectProgress");
	TimeLine.AddInterpFloat(CombatModeCurve, progressFunction, FName{ TEXT("EffectProgress") });
}

void APlayerCharacter::BeginPlay()
{
	TimeLine.PlayFromStart();
}

void APlayerCharacter::EffectProgress(float Value)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("EFFECT PROGRESS"));
}




Can anyone help me please? Thanks in advance!

As far as I know Timelines don’t really ‘exist’ in C++, they’re just a special type of node that creates a bunch of delegates to different events, though I could be wrong here. This would also explain why you can’t generate them in anything but the Event Graph. If someone can correct me on that though, I’m all ears.

You can use the ‘GetValueAtTime()’ (it’s called something like that) on the curve to get the value at any particular interval.

Hey there,

Timelines working well in c++ but
additionally to blueprint in c++ you need to tick the Timeline.

so override the Tick function for your actor

and inside:




void APlayerCharacter::Tick()
{

if (Timeline.IsPlaying())
{
Timeline.TickTimeline();
}



regards
Wallhalla

edit: The topic says “Error when add CurveFloat”, but you dont write anything about an error at all.

edit edit: btw. you dont need to call the function “EffectProgress” you can call it whatever you want it was just an example in the forums^^
you can even add a delegate to the Timeline which is called when the Timeline has finished, which might be useful too :wink:

Thanks all!
Walhalla sorry for the topic title and thanks for your answer! I’m not in front of my computer, but when I can I will try to add timeline method to Tick.

I have added tick to Timeline, but my game now crash… This is my code now:



APlayerCharacter::APlayerCharacter()
{
	TimeLine = FTimeline{};
	FOnTimelineFloat progressFunction;
	progressFunction.BindUFunction(this, "EffectProgress");
	TimeLine.AddInterpFloat(CombatModeCurve, progressFunction, FName{ TEXT("EffectProgress") });
}

void APlayerCharacter::BeginPlay()
{
	TimeLine.PlayFromStart();
}

void APlayerCharacter::EffectProgress(float Value)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("EFFECT PROGRESS"));
}
void APlayerCharacter::Tick(float DeltaSeconds)
{
    if (Timeline.IsPlaying())
	{
		Timeline.TickTimeline(DeltaSeconds);
	}
}



What is the problem? Thanks in advance.

this is error :




Access violation - code c0000005 (first/second chance not available)

""

UE4Editor_Engine!UCurveBase::GetTimeRange() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\curvebase.cpp:844]
UE4Editor_Engine!FTimeline::GetLastKeyframeTime() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	imeline.cpp:529]
UE4Editor_Engine!FTimeline::GetTimelineLength() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	imeline.cpp:463]
UE4Editor_Engine!FTimeline::TickTimeline() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	imeline.cpp:366]
UE4Editor_NeverEndingNightmare!APlayerCharacter::Tick() [c:\users\raffaele\documents\unreal projects
everendingnightmare\source
everendingnightmare\playercharacter.cpp:49]
UE4Editor_Engine!AActor::TickActor() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\actor.cpp:670]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\actor.cpp:105]
UE4Editor_Engine!FTickTaskSequencer::FTickFunctionTask::DoTask() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	icktaskmanager.cpp:113]
UE4Editor_Engine!TGraphTask<FTickTaskSequencer::FTickFunctionTask>::ExecuteTask() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\async	askgraphinterfaces.h:753]
UE4Editor_Core!FTaskThread::ProcessTasks() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\async	askgraph.cpp:430]
UE4Editor_Core!FTaskThread::ProcessTasksUntilQuit() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\async	askgraph.cpp:273]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\async	askgraph.cpp:991]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	icktaskmanager.cpp:243]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	icktaskmanager.cpp:643]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\leveltick.cpp:697]
UE4Editor_Engine!UWorld::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\leveltick.cpp:1181]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\unrealed\private\editorengine.cpp:1339]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\unrealed\private\unrealedengine.cpp:366]
UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launchengineloop.cpp:2359]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]




I have solved! I added



const ConstructorHelpers::FObjectFinder<UCurveFloat> Curve(TEXT("CurveFloat'/Game/OwnStuff/EffectCurve.EffectCurve'"));


in constructor and now works fine!

Thanks all!

Oh yeah, did you actually specify the curve asset? Otherwise you’ll get a nullptr crash. That would explain it :wink:

hey

i would agree with TheJamshś answer.

And i dont think that your FObjectfinder solution is nesessary at all.

Please make sure you set the Curve inside your CHaracter blueprint.

and additionally add a nullptr check for your curve before you call the play timeline.

And i just saw that you set up everything inside the ctor.
I assume that this is too early for the timeline and delegates to be set up,

so use the Event BeginPlay or maybe PostInitializeComponents, but i think BeginPlay should be enough.

best regards
Wallhalla