From c0686d5a365342cbd27687d78890879a7aa4c36c Mon Sep 17 00:00:00 2001 From: Pravus Date: Mon, 27 Nov 2023 18:19:11 +0100 Subject: [PATCH] mini refactor to allow returning raycast results with partial data when hitting a non-sdk7-entity collider --- .../Systems/RaycastSystem/ECSRaycastSystem.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/unity-renderer/Assets/DCLPlugins/ECS7/Systems/RaycastSystem/ECSRaycastSystem.cs b/unity-renderer/Assets/DCLPlugins/ECS7/Systems/RaycastSystem/ECSRaycastSystem.cs index 029ccb4618..a5190dc733 100644 --- a/unity-renderer/Assets/DCLPlugins/ECS7/Systems/RaycastSystem/ECSRaycastSystem.cs +++ b/unity-renderer/Assets/DCLPlugins/ECS7/Systems/RaycastSystem/ECSRaycastSystem.cs @@ -210,21 +210,24 @@ private Ray CreateRay(IParcelScene scene, IDCLEntity entity, PBRaycast model) private RaycastHit CreateSDKRaycastHit(IParcelScene scene, PBRaycast model, UnityEngine.RaycastHit unityRaycastHit, KeyValuePair? hitEntity, Vector3 globalOrigin) { - if (hitEntity == null) return null; - - // TODO: figure out how we can cache or pool this hit instance to reduce allocations. - // since is part of a protobuf message it life span is uncertain, it could be disposed - // after message is sent to the scene or dropped for a new message RaycastHit hit = new RaycastHit(); - IDCLEntity entity = hitEntity.Value.Key; - uint collisionMask = hitEntity.Value.Value; - // hitEntity has to be evaluated since 'Default' layer represents a combination of ClPointer - // and ClPhysics, and 'SDKCustomLayer' layer represents 8 different SDK layers: ClCustom1~8 - if ((model.GetCollisionMask() & collisionMask) == 0) - return null; + if (hitEntity != null) // SDK7 entity, otherwise the ray hit an SDK6 entity + { + // TODO: figure out how we can cache or pool this hit instance to reduce allocations. + // since is part of a protobuf message it life span is uncertain, it could be disposed + // after message is sent to the scene or dropped for a new message + IDCLEntity entity = hitEntity.Value.Key; + uint collisionMask = hitEntity.Value.Value; + + // hitEntity has to be evaluated since 'Default' layer represents a combination of ClPointer + // and ClPhysics, and 'SDKCustomLayer' layer represents 8 different SDK layers: ClCustom1~8 + if ((model.GetCollisionMask() & collisionMask) == 0) + return null; + + hit.EntityId = (uint)entity.entityId; + } - hit.EntityId = (uint)entity.entityId; hit.MeshName = unityRaycastHit.collider.name; hit.Length = unityRaycastHit.distance; hit.GlobalOrigin = globalOrigin;