I had already created a topic about how i can start a function after each physics run and there i was pointed to FTickFunction. But since this is now specifically about my FTickFunction problems i have created a new topic.
I have looked at the documentation [1], found this topic [2], tried to look at the source text and out of desperation i asked ChatGPT (yes i know but i was desperate) because its database is very large but i can’t get any further.
What i think i have understood so far is that i can create my FTickFunction structur and define there e.g. in which tick group it should be executed. Later i can then declare this structure in any class and specify my function that should be executed with every tick.
(if this is wrong, please correct me)
So far i have created the following source text for the creation of the structure:
// .h
#pragma once
#include "CoreMinimal.h"
#include "Engine/EngineBaseTypes.h"
USTRUCT()
struct P0_API FTickPostPhysics : public FTickFunction
{
//i have taken the following from the topic i found
GENERATED_USTRUCT_BODY()
// Delegate allows you to bind any function to this ticker
DECLARE_DELEGATE_OneParam(TickDelegate, float);
TickDelegate TickFunction;
virtual void ExecuteTick(float DeltaTime, enum ELevelTick TickType, ENamedThreads::Type CurrentThread, const FGraphEventRef& MyCompletionGraphEvent) override
{
TickFunction.ExecuteIfBound(DeltaTime);
}
virtual FString DiagnosticMessage() override { return TEXT("FTickPostPhysics"); }
virtual FName DiagnosticContext(bool bDetailed) override { return FName(TEXT("FTickPostPhysics")); }
// set the tick group to TG_PostPhysics to execute after each physics tick (this is what i tried to read from the source text)
virtual ETickingGroup GetTickingGroup() const override
{
return TG_PostPhysics;
}
/*
* idk if i need this later (ChatGPT has recommended it to me)
*
virtual TStatId GetStatId() const override
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FTickPostPhysics, STATGROUP_Tickables);
}
virtual TFunctionRef<void(float)> GetExecuteFunction() override
{
return [this](float DeltaTime) { ExecuteTick(DeltaTime, LEVELTICK_All, ENamedThreads::GameThread, FGraphEventRef()); };
}
*/
};
However, the following errors occur during compiling:
CompilerResultsLog: In file included from /home/abaddev/Documents/UE5/P0/Intermediate/Build/Linux/UnrealEditor/Inc/P0/UHT/FTickPostPhysics.gen.cpp:8:
CompilerResultsLog: /home/abaddev/Documents/UE5/P0/Source/P0/FTickPostPhysics.h:11:2: error: a type specifier is required for all declarations
CompilerResultsLog: GENERATED_USTRUCT_BODY()
CompilerResultsLog: ^
CompilerResultsLog: /mnt/seagate4tb/UE5/Engine/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:710:37: note: expanded from macro 'GENERATED_USTRUCT_BODY'
CompilerResultsLog: #define GENERATED_USTRUCT_BODY(...) GENERATED_BODY()
CompilerResultsLog: ^
CompilerResultsLog: /mnt/seagate4tb/UE5/Engine/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:708:29: note: expanded from macro 'GENERATED_BODY'
CompilerResultsLog: #define GENERATED_BODY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY);
CompilerResultsLog: ^
CompilerResultsLog: /mnt/seagate4tb/UE5/Engine/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:703:37: note: expanded from macro 'BODY_MACRO_COMBINE'
CompilerResultsLog: #define BODY_MACRO_COMBINE(A,B,C,D) BODY_MACRO_COMBINE_INNER(A,B,C,D)
CompilerResultsLog: ^
CompilerResultsLog: /mnt/seagate4tb/UE5/Engine/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:702:43: note: expanded from macro 'BODY_MACRO_COMBINE_INNER'
CompilerResultsLog: #define BODY_MACRO_COMBINE_INNER(A,B,C,D) A##B##C##D
CompilerResultsLog: ^
CompilerResultsLog: <scratch space>:5:1: note: expanded from here
CompilerResultsLog: FID_Engine_Source_Runtime_Experimental_Chaos_Public_PhysicsCoreTypes_h_11_GENERATED_BODY
CompilerResultsLog: ^
CompilerResultsLog: In file included from /home/abaddev/Documents/UE5/P0/Intermediate/Build/Linux/UnrealEditor/Inc/P0/UHT/FTickPostPhysics.gen.cpp:8:
CompilerResultsLog: /home/abaddev/Documents/UE5/P0/Source/P0/FTickPostPhysics.h:29:24: error: 'GetTickingGroup' marked 'override' but does not override any member functions
CompilerResultsLog: virtual ETickingGroup GetTickingGroup() const override
CompilerResultsLog: ^
CompilerResultsLog: /home/abaddev/Documents/UE5/P0/Intermediate/Build/Linux/UnrealEditor/Inc/P0/UHT/FTickPostPhysics.gen.cpp:20:40: error: out-of-line definition of 'StaticStruct' does not match any declaration in 'FTickPostPhysics'
CompilerResultsLog: class UScriptStruct* FTickPostPhysics::StaticStruct()
CompilerResultsLog: ^~~~~~~~~~~~
CompilerResultsLog: /home/abaddev/Documents/UE5/P0/Intermediate/Build/Linux/UnrealEditor/Inc/P0/UHT/FTickPostPhysics.gen.cpp:30:27: error: call to non-static member function without an object argument
CompilerResultsLog: return FTickPostPhysics::StaticStruct();
CompilerResultsLog: ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
CompilerResultsLog: /home/abaddev/Documents/UE5/P0/Intermediate/Build/Linux/UnrealEditor/Inc/P0/UHT/FTickPostPhysics.gen.cpp:75:23: error: call to non-static member function without an object argument
CompilerResultsLog: { FTickPostPhysics::StaticStruct, Z_Construct_UScriptStruct_FTickPostPhysics_Statics::NewStructOps, TEXT("TickPostPhysics"), &Z_Registration_Info_UScriptStruct_TickPostPhysics, CONSTRUCT_RELOAD_VERSION_INFO(FStructReloadVersionInfo, sizeof(FTickPostPhysics), 1909861675U) },
CompilerResultsLog: ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
CompilerResultsLog: /home/abaddev/Documents/UE5/P0/Intermediate/Build/Linux/UnrealEditor/Inc/P0/UHT/FTickPostPhysics.gen.cpp:79:122: error: no matching function for call to 'UEArrayCountHelper'
CompilerResultsLog: Z_CompiledInDeferFile_FID_home_abaddev_Dokumente_UE5_P0_Source_P0_FTickPostPhysics_h_Statics::ScriptStructInfo, UE_ARRAY_COUNT(Z_CompiledInDeferFile_FID_home_abaddev_Dokumente_UE5_P0_Source_P0_FTickPostPhysics_h_Statics::ScriptStructInfo),
CompilerResultsLog: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CompilerResultsLog: /mnt/seagate4tb/UE5/Engine/Engine/Source/Runtime/Core/Public/Templates/UnrealTemplate.h:197:41: note: expanded from macro 'UE_ARRAY_COUNT'
CompilerResultsLog: #define UE_ARRAY_COUNT( array ) (sizeof(UEArrayCountHelper(array)) - 1)
CompilerResultsLog: ^~~~~~~~~~~~~~~~~~
CompilerResultsLog: /mnt/seagate4tb/UE5/Engine/Engine/Source/Runtime/Core/Public/Templates/UnrealTemplate.h:190:7: note: candidate template ignored: substitution failure [with T = const FStructRegisterCompiledInInfo[]]: invalid application of 'sizeof' to an incomplete type 'const FStructRegisterCompiledInInfo[]'
CompilerResultsLog: auto UEArrayCountHelper(T& t) -> typename TEnableIf<__is_array(T), char(&)[sizeof(t) / sizeof(t[0]) + 1]>::Type;
CompilerResultsLog: ^ ~
CompilerResultsLog: 6 errors generated.
FYI: As you can probably tell from the file paths, i’m developing on GNU/Linux and since VS Code doesn’t work properly with UE5 because it shows errors where there are definitely no errors, i’m currently developing with a relatively simple editor which only recognises the C++ language.
If someone could help me and explain how (if i understood it correctly) the structur is used to execute a function later, that would be very nice because i’m quite stuck.
with kind regards
[1] FTickFunction | Unreal Engine 5.2 Documentation
[2] How can I get started with FTickFunctions?