mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Add helper to set dynamic sized nav meshes
This commit is contained in:
parent
df40ca92e5
commit
672b199612
@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
#include "StevesDynamicNavMeshVolume.h"
|
||||||
|
|
||||||
|
#include "NavigationSystem.h"
|
||||||
|
#include "Components/BrushComponent.h"
|
||||||
|
#include "PhysicsEngine/BodySetup.h"
|
||||||
|
|
||||||
|
|
||||||
|
AStevesDynamicNavMeshVolume::AStevesDynamicNavMeshVolume()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AStevesDynamicNavMeshVolume::SetLocationAndDimensions(const FVector& Location, const FVector& NewDimensions)
|
||||||
|
{
|
||||||
|
SetActorLocation(Location);
|
||||||
|
UpdateDimensions(NewDimensions);
|
||||||
|
NotifyNavSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AStevesDynamicNavMeshVolume::SetDimensions(const FVector& NewDimensions)
|
||||||
|
{
|
||||||
|
UpdateDimensions(NewDimensions);
|
||||||
|
NotifyNavSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AStevesDynamicNavMeshVolume::UpdateDimensions(const FVector& NewDimensions)
|
||||||
|
{
|
||||||
|
// Volumes are built using UCubeBuilder, but we can't use that class at runtime (Editor only)
|
||||||
|
// It generates the 6 faces as polys, like old BSP stuff. No idea why for a cube, we don't need that here
|
||||||
|
// Just box it baby
|
||||||
|
|
||||||
|
if (auto Body = GetBrushComponent()->GetBodySetup())
|
||||||
|
{
|
||||||
|
Body->AggGeom.ConvexElems.Empty();
|
||||||
|
if (Body->AggGeom.BoxElems.Num() == 0)
|
||||||
|
{
|
||||||
|
Body->AggGeom.BoxElems.Emplace();
|
||||||
|
}
|
||||||
|
auto& Box = Body->AggGeom.BoxElems[0];
|
||||||
|
Box.X = NewDimensions.X;
|
||||||
|
Box.Y = NewDimensions.Y;
|
||||||
|
Box.Z = NewDimensions.Z;
|
||||||
|
GetBrushComponent()->Bounds = FBoxSphereBounds(FVector::ZeroVector, NewDimensions*0.5f, NewDimensions.GetMax()*0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AStevesDynamicNavMeshVolume::NotifyNavSystem()
|
||||||
|
{
|
||||||
|
if (UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld()))
|
||||||
|
{
|
||||||
|
NavSys->OnNavigationBoundsUpdated(this);
|
||||||
|
}
|
||||||
|
}
|
24
Source/StevesUEHelpers/Public/StevesDynamicNavMeshVolume.h
Normal file
24
Source/StevesUEHelpers/Public/StevesDynamicNavMeshVolume.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "NavMesh/NavMeshBoundsVolume.h"
|
||||||
|
#include "StevesDynamicNavMeshVolume.generated.h"
|
||||||
|
|
||||||
|
/// NavMesh bounds that can be changed at runtime (requires that your NavMesh data Runtime Generation is set to Dynamic)
|
||||||
|
UCLASS()
|
||||||
|
class STEVESUEHELPERS_API AStevesDynamicNavMeshVolume : public ANavMeshBoundsVolume
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
AStevesDynamicNavMeshVolume();
|
||||||
|
|
||||||
|
void SetLocationAndDimensions(const FVector& Location, const FVector& NewDimensions);
|
||||||
|
void SetDimensions(const FVector& NewDimensions);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void UpdateDimensions(const FVector& NewDimensions);
|
||||||
|
void NotifyNavSystem();
|
||||||
|
};
|
@ -39,7 +39,8 @@ public class StevesUEHelpers : ModuleRules
|
|||||||
{
|
{
|
||||||
"RenderCore",
|
"RenderCore",
|
||||||
"PhysicsCore",
|
"PhysicsCore",
|
||||||
"Chaos"
|
"Chaos",
|
||||||
|
"NavigationSystem"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user