Fix creating virtual terrain collision of actor that is not in a game

This commit is contained in:
Wojtek Figat
2024-05-05 22:50:12 +02:00
parent 9d830eb1e2
commit db8adf7d96
2 changed files with 12 additions and 1 deletions

View File

@@ -12,6 +12,7 @@
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Physics/PhysicsScene.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Renderer/GlobalSignDistanceFieldPass.h"
#include "Engine/Renderer/GI/GlobalSurfaceAtlasPass.h"
@@ -807,6 +808,15 @@ void Terrain::OnEnable()
#if TERRAIN_USE_PHYSICS_DEBUG
GetSceneRendering()->AddPhysicsDebug<Terrain, &Terrain::DrawPhysicsDebug>(this);
#endif
void* scene = GetPhysicsScene()->GetPhysicsScene();
for (int32 i = 0; i < _patches.Count(); i++)
{
auto patch = _patches[i];
if (patch->_physicsActor)
{
PhysicsBackend::AddSceneActor(scene, patch->_physicsActor);
}
}
// Base
Actor::OnEnable();

View File

@@ -2126,7 +2126,8 @@ void TerrainPatch::CreateCollision()
void* scene = _terrain->GetPhysicsScene()->GetPhysicsScene();
_physicsActor = PhysicsBackend::CreateRigidStaticActor(nullptr, terrainTransform.LocalToWorld(_offset), terrainTransform.Orientation, scene);
PhysicsBackend::AttachShape(_physicsShape, _physicsActor);
PhysicsBackend::AddSceneActor(scene, _physicsActor);
if (_terrain->IsDuringPlay())
PhysicsBackend::AddSceneActor(scene, _physicsActor);
}
bool TerrainPatch::CreateHeightField()