Skip to content

Commit

Permalink
Fixed a bug in the GenerateDungeon function that caused StaticMesh ge…
Browse files Browse the repository at this point in the history
…neration to fail.
  • Loading branch information
shun126 committed Sep 27, 2024
1 parent feb5da3 commit 21fa5c5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Change Log - Procedural 3D Dungeon Generator Plug-in

## Unreleased-1.6.* (37)
## Unreleased-1.6.* (38)
### Changes
### 変更点

## 20240926-1.6.8 (37)
### Changes
* Fixed a bug in the GenerateDungeon function that caused StaticMesh generation to fail.
### 変更点
* GenerateDungeon関数でStaticMeshの生成に失敗する不具合を修正

## 20240915-1.6.7 (36)
### Changes
* Added support for indoor staircase generation
Expand Down
4 changes: 2 additions & 2 deletions DungeonGenerator.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 36,
"VersionName": "1.6.7",
"Version": 37,
"VersionName": "1.6.8",
"FriendlyName": "Procedural 3D Dungeon Generator",
"Description": "Procedural 3D dungeon generator plugin. Easy generation of levels, mini-maps and missions.",
"Category": "Procedural",
Expand Down
54 changes: 34 additions & 20 deletions Source/DungeonGenerator/Private/DungeonActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ void ADungeonActor::FitNavMeshBoundsVolume()
if (USceneComponent* rootComponent = navMeshBoundsVolume->GetRootComponent())
{
const EComponentMobility::Type mobility = rootComponent->Mobility;
rootComponent->SetMobility(EComponentMobility::Stationary);
rootComponent->SetMobility(EComponentMobility::Movable);

navMeshBoundsVolume->SetActorLocation(boundingCenter);
navMeshBoundsVolume->SetActorScale3D(FVector::OneVector);
Expand Down Expand Up @@ -1317,24 +1317,34 @@ CRC32の計算を行うのでサーバーとクライアントの同期ずれを
*/
AStaticMeshActor* ADungeonActor::SpawnStaticMeshActor(UStaticMesh* staticMesh, const FString& folderPath, const FTransform& transform, const ESpawnActorCollisionHandlingMethod spawnActorCollisionHandlingMethod) const
{
AStaticMeshActor* actor = SpawnActorImpl<AStaticMeshActor>(folderPath, transform, nullptr, spawnActorCollisionHandlingMethod);
if (!IsValid(actor))
AStaticMeshActor* actor = SpawnActorDeferredImpl<AStaticMeshActor>(folderPath, transform, nullptr, spawnActorCollisionHandlingMethod);
if (IsValid(actor) == false)
return nullptr;

UStaticMeshComponent* mesh = actor->GetStaticMeshComponent();
if (IsValid(mesh))
mesh->SetStaticMesh(staticMesh);
UStaticMeshComponent* staticMeshComponent = actor->GetStaticMeshComponent();
if (IsValid(staticMeshComponent) == true)
{
if (const UWorld* world = actor->GetWorld())
{
if (world->HasBegunPlay() == true)
actor->SetMobility(EComponentMobility::Movable);
}

staticMeshComponent->SetStaticMesh(staticMesh);
}

// 処理負荷制御を追加
UDungeonComponentActivatorComponent* dungeonComponentActivatorComponent = NewObject<UDungeonComponentActivatorComponent>(actor);
if (IsValid(dungeonComponentActivatorComponent))
if (IsValid(dungeonComponentActivatorComponent) == true)
{
dungeonComponentActivatorComponent->SetEnableCollisionEnableControl(false);

actor->AddInstanceComponent(dungeonComponentActivatorComponent);
dungeonComponentActivatorComponent->RegisterComponent();
}

actor->FinishSpawning(transform, true);

// CRC32を記録(必ずサーバーとクライアント両方で計算しないとCRC32が一致しなくなる)
mCrc32AtCreation = ADungeonActorBase::GenerateCrc32(transform, mCrc32AtCreation);

Expand All @@ -1351,7 +1361,7 @@ ADungeonDoorBase* ADungeonActor::SpawnDoorActor(UClass* actorClass, const FTrans
{
actor->InvokeInitialize(GetRandom(), props);

actor->FinishSpawning(transform);
actor->FinishSpawning(transform, true);

if (IsValid(ownerActor))
ownerActor->AddDungeonDoor(actor);
Expand Down Expand Up @@ -1448,30 +1458,34 @@ void ADungeonActor::Clear()

FTransform ADungeonActor::GetStartTransform() const
{
if (IsValid(mParameter) && mGenerator != nullptr && mGenerator->GetLastError() == dungeon::Generator::Error::Success)
{
return FTransform(*mGenerator->GetStartPoint() * mParameter->GetGridSize().To3D());
}
return FTransform::Identity;
return FTransform(GetStartLocation());
}

FTransform ADungeonActor::GetGoalTransform() const
{
if (IsValid(mParameter) && mGenerator != nullptr && mGenerator->GetLastError() == dungeon::Generator::Error::Success)
{
return FTransform(*mGenerator->GetGoalPoint() * mParameter->GetGridSize().To3D());
}
return FTransform::Identity;
return FTransform(GetGoalLocation());
}

FVector ADungeonActor::GetStartLocation() const
{
return GetStartTransform().GetLocation();
if (IsValid(mParameter) && mGenerator != nullptr && mGenerator->GetLastError() == dungeon::Generator::Error::Success)
{
FVector location = *mGenerator->GetStartPoint() * mParameter->GetGridSize().To3D();
location += GetActorLocation();
return location;
}
return FVector::ZeroVector;
}

FVector ADungeonActor::GetGoalLocation() const
{
return GetGoalTransform().GetLocation();
if (IsValid(mParameter) && mGenerator != nullptr && mGenerator->GetLastError() == dungeon::Generator::Error::Success)
{
FVector location = *mGenerator->GetGoalPoint() * mParameter->GetGridSize().To3D();
location += GetActorLocation();
return location;
}
return FVector::ZeroVector;
}

FBox ADungeonActor::CalculateBoundingBox() const
Expand Down
2 changes: 1 addition & 1 deletion Source/DungeonGenerator/Public/DungeonActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ inline T* ADungeonActor::SpawnActorImpl(const FString& folderPath, const FTransf
template<typename T>
inline T* ADungeonActor::SpawnActorDeferredImpl(const FString& folderPath, const FTransform& transform, AActor* ownerActor, const ESpawnActorCollisionHandlingMethod spawnActorCollisionHandlingMethod) const
{
return SpawnActorImpl(T::StaticClass(), folderPath, transform, spawnActorCollisionHandlingMethod);
return SpawnActorDeferredImpl<T>(T::StaticClass(), folderPath, transform, ownerActor, spawnActorCollisionHandlingMethod);
}

template<typename T>
Expand Down

0 comments on commit 21fa5c5

Please sign in to comment.