in Ambit/Source/Ambit/Actors/Spawners/SpawnWithHoudini.cpp [74:129]
void ASpawnWithHoudini::GenerateObstacles()
{
Random.Initialize(RandomSeed);
const bool bDidClear = ClearObstacles();
if (!bDidClear)
{
return;
}
const TArray<AActor*> SurfaceActors = AmbitWorldHelpers::GetActorsByMatchBy(
MatchBy, SurfaceNamePattern, SurfaceTags);
UE_LOG(LogAmbit, Display, TEXT("Matching surface actors: %i"), SurfaceActors.Num());
TArray<FTransform> LocationsToSpawn = AmbitWorldHelpers::GenerateRandomLocationsFromActors(
SurfaceActors, RandomSeed, DensityMin, DensityMax);
UWorld* World = GetWorld();
if (CurrentGeneration == NotGenerated)
{
if (World != nullptr && (World->IsPlayInEditor() || World->IsPlayInPreview()))
{
CurrentGeneration = FromRuntime;
}
else
{
CurrentGeneration = FromEditor;
}
}
HoudiniApi->CreateSession();
for (const FTransform& Transform : LocationsToSpawn)
{
const int32 Index = Random.RandRange(0, HoudiniAssetDetails.Num() - 1);
UHoudiniAsset* IndividualHDA = HoudiniAssetDetails[Index].HDAToLoad;
// Check whether the HDA Asset has been selected
if (IndividualHDA != nullptr)
{
FString BakePath = GetBakePathRelative();
UHoudiniPublicAPIAssetWrapper* SpawnedActor = HoudiniApi->InstantiateAsset(
IndividualHDA, Transform, World, nullptr, false, false, BakePath);
if (SpawnedActor != nullptr)
{
SpawnedActor->GetOnPreInstantiationDelegate().AddUniqueDynamic(
this, &ASpawnWithHoudini::AssetPreInstantiation_DelegateHandler);
SpawnedActor->GetOnPostProcessingDelegate().AddUniqueDynamic(
this, &ASpawnWithHoudini::PostProcessing_DelegateHandler);
SpawnedActor->GetOnPostBakeDelegate().AddUniqueDynamic(
this, &ASpawnWithHoudini::PostBake_DelegateHandler);
HoudiniAssetDetails[Index].SpawnedActors.Add(SpawnedActor);
}
}
}
}