Hi! I’m pretty new in using delegates in Unreal and I’m kind of stuck. So I have a class where I defined a delegate and its constructor takes it in as a parameter: WorldGeneration.h
DECLARE_DELEGATE_TwoParams(FWorldGenerationCallback, TArray&, MeshData*);
class PROCEDURALWORLD_API WorldGeneration: public FRunnable
{
public:
WorldGeneration(WorldStats* stats, FWorldGenerationCallback& callback);
~WorldGeneration();
//some other functions
private:
TArray mGrid;
WorldStats* mStats;
FWorldGenerationCallback mFinishCallback;
MeshData* mMeshData;
};
WorldGeneration.cpp:
WorldGeneration::WorldGeneration(WorldStats* stats, FWorldGenerationCallback& callback)
{
mStats = stats;
//delegate is used in some other function inside WorldGeneration class with .Execute
mFinishCallback = callback;
}
Now inside the other class I’m trying to create the WorldGeneration instance and send the function I want to be using as delegate GeneratedWorld.cpp
void AGeneratedWorld::LoadMeshData(TArray& createdGrid, MeshData* meshData)
{
//function I want to send as delegate
}
void AGeneratedWorld::RequestWorldGeneration()
{
WorldStats* stats = new WorldStats();
//more code
//I don't know how to send the LoadMeshData function
WorldGeneration* worldGeneration = new WorldGeneration(stats, &AGeneratedWorld::LoadMeshData);
}
I know that in Unity you can just pass in the name of the function like I’ve done in the code above and it works normally… What am I doing wrong?