I’m working on a feature to move my procedural foliage generator to the player’s position when certain conditions are met. I’ve got this code so far. I compiles and runs, but no foliage is generated.
void AddFoliageInstancesCallback(const TArray<FDesiredFoliageInstance>& Instances)
{
// Not sure what to do here
}
void AFoliageManager::ReRunSimulation()
{
if (ProceduralFoliageVolume->IsValidLowLevel())
{
ProceduralFoliageGenerator = ProceduralFoliageVolume->GetComponentByClass<UProceduralFoliageComponent>();
}
if (ProceduralFoliageGenerator)
{
FVector PlayerPosition = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
PlayerPosition.Z = 820;
ProceduralFoliageVolume->SetActorLocation(PlayerPosition);
// Create a TFunctionRef from the function
TFunctionRef<void(const TArray<FDesiredFoliageInstance>&)> FuncRef =
TFunctionRef<void(const TArray<FDesiredFoliageInstance>&)>(AddFoliageInstancesCallback);
if (ProceduralFoliageGenerator->ResimulateProceduralFoliage(FuncRef))
{
UE_LOG(LogTemp, Log, TEXT("Foliage generation successful"));
}
}
}
I suppose I’m missing a step or something, because I also don’t really know what to do in the AddInstanceFunc callback. Alas, the documentation doesn’t go into any detail. Has anyone tried something like this before? Any pointers?