Debounced SplineNetwork rebuild on spline point changes
- ScheduleNetworkRebuild() called after AddPoint, RemovePoint, SetAllPointLocations - 0.5s debounce timer avoids redundant rebuilds during rapid editing - AI NPCs now detect and follow splines placed in the editor immediately Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -124,11 +124,30 @@ void APS_BehaviorEditor_AISpline::BeginPlay()
|
|||||||
|
|
||||||
// ---- Point manipulation ----
|
// ---- Point manipulation ----
|
||||||
|
|
||||||
|
void APS_BehaviorEditor_AISpline::ScheduleNetworkRebuild()
|
||||||
|
{
|
||||||
|
if (UWorld* World = GetWorld())
|
||||||
|
{
|
||||||
|
World->GetTimerManager().ClearTimer(NetworkRebuildTimer);
|
||||||
|
World->GetTimerManager().SetTimer(NetworkRebuildTimer, [WeakWorld = TWeakObjectPtr<UWorld>(World)]()
|
||||||
|
{
|
||||||
|
if (UWorld* W = WeakWorld.Get())
|
||||||
|
{
|
||||||
|
if (UPS_AI_Behavior_SplineNetwork* Network = W->GetSubsystem<UPS_AI_Behavior_SplineNetwork>())
|
||||||
|
{
|
||||||
|
Network->RebuildNetwork();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0.5f, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void APS_BehaviorEditor_AISpline::AddPoint(const FVector& WorldPosition)
|
void APS_BehaviorEditor_AISpline::AddPoint(const FVector& WorldPosition)
|
||||||
{
|
{
|
||||||
SplineComp->AddSplinePoint(WorldPosition, ESplineCoordinateSpace::World, true);
|
SplineComp->AddSplinePoint(WorldPosition, ESplineCoordinateSpace::World, true);
|
||||||
PointHandles.Add(CreatePointHandle(WorldPosition));
|
PointHandles.Add(CreatePointHandle(WorldPosition));
|
||||||
UpdateVisualization();
|
UpdateVisualization();
|
||||||
|
ScheduleNetworkRebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APS_BehaviorEditor_AISpline::MovePoint(int32 Index, const FVector& NewWorldPosition)
|
void APS_BehaviorEditor_AISpline::MovePoint(int32 Index, const FVector& NewWorldPosition)
|
||||||
@@ -152,6 +171,7 @@ void APS_BehaviorEditor_AISpline::RemovePoint(int32 Index)
|
|||||||
PointHandles.RemoveAt(Index);
|
PointHandles.RemoveAt(Index);
|
||||||
}
|
}
|
||||||
UpdateVisualization();
|
UpdateVisualization();
|
||||||
|
ScheduleNetworkRebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 APS_BehaviorEditor_AISpline::GetNumPoints() const
|
int32 APS_BehaviorEditor_AISpline::GetNumPoints() const
|
||||||
@@ -188,6 +208,7 @@ void APS_BehaviorEditor_AISpline::SetAllPointLocations(const TArray<FVector>& Po
|
|||||||
SplineComp->UpdateSpline();
|
SplineComp->UpdateSpline();
|
||||||
RebuildHandles();
|
RebuildHandles();
|
||||||
UpdateVisualization();
|
UpdateVisualization();
|
||||||
|
ScheduleNetworkRebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APS_BehaviorEditor_AISpline::InsertPoint(int32 Index, const FVector& WorldPosition)
|
void APS_BehaviorEditor_AISpline::InsertPoint(int32 Index, const FVector& WorldPosition)
|
||||||
@@ -196,7 +217,7 @@ void APS_BehaviorEditor_AISpline::InsertPoint(int32 Index, const FVector& WorldP
|
|||||||
Index = FMath::Clamp(Index, 0, GetNumPoints());
|
Index = FMath::Clamp(Index, 0, GetNumPoints());
|
||||||
TArray<FVector> Points = GetAllPointLocations();
|
TArray<FVector> Points = GetAllPointLocations();
|
||||||
Points.Insert(WorldPosition, Index);
|
Points.Insert(WorldPosition, Index);
|
||||||
SetAllPointLocations(Points);
|
SetAllPointLocations(Points); // Already calls ScheduleNetworkRebuild
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 APS_BehaviorEditor_AISpline::FindInsertIndex(const FVector& WorldLocation) const
|
int32 APS_BehaviorEditor_AISpline::FindInsertIndex(const FVector& WorldLocation) const
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ private:
|
|||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TObjectPtr<UMaterialInstanceDynamic> CenterCubeMat;
|
TObjectPtr<UMaterialInstanceDynamic> CenterCubeMat;
|
||||||
|
|
||||||
|
/** Schedule a debounced SplineNetwork rebuild. */
|
||||||
|
void ScheduleNetworkRebuild();
|
||||||
|
FTimerHandle NetworkRebuildTimer;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
TObjectPtr<UPS_Editor_SpawnableComponent> SpawnableComp;
|
TObjectPtr<UPS_Editor_SpawnableComponent> SpawnableComp;
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
|||||||
Reference in New Issue
Block a user