Hey If you want your any class functions to be called by FWorldDelegates,
These are the steps to follow:
- create a class and in the header file
Let’s create an actor class
#pragma once
#include "CoreMinimal.h"
#include "Engine/World.h" /// include the engine delegates here
#include "GameFramework/Actor.h"
#include "HelloWorldActor.generated.h"
- create a function that needs to be called in the FworldDelegates
in the header file
void myfunctionFD(UWorld* a, ELevelTick b, float c );
in source file
void myfunctionFD(UWorld* a, ELevelTick b, float c )
{
UE_LOG(LogTemp, Warning, TEXT("Hello World ! , myfunctionFD is being called by the engine delegates "));
}
- Now, it’s time to call assign this function to FWorldDelegates
in the source file
say when the beginPlay function is being called,
I want to attach " myfunctionFD " function to one of the FWorldDelegates
here the code
void HelloWorldActor::BeginPlay()
{
Super::BeginPlay();
FWorldDelegates::OnWorldPostActorTick.AddUObject(this, &HelloWorldActor::myfunctionFD );
}
If you noticed my function has a parameter that obeys the rule of delegate “OnWorldPostActorTick” parameters.
And when you want your functions to be called in another engine delegates, all of them need to follow the delegates parameters.
You can find those parameters when you writing in your IDE’s IntelliSense
or in the world.h header
/Engine/Source/Runtime/Engine/Classes/Engine/World.h