Hello Everyone,
I’m encountering an issue where baked lightmaps are no longer displayed after I close the Subscene. This only occurs when activating a BakingSystem that divides the World into streamable sections.
Has anyone experienced similar issues or have any insights into why this might happen?
Here’s the relevant code snippet for the system:
/// <summary>
/// This system affects a section to all entities in the World depending on their location
/// </summary>
[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
partial struct SceneStreamingBakingSystem : ISystem
{
private struct EntitySection
{
public Entity SectionEntity;
public int Index;
}
//Create a native hashmap with region as key and entity section as value
private NativeHashMap<RegionIndex, EntitySection> _sectionHashMap;
private EntityQuery _sectionQuery;
private EntityQuery _query;
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
//Init the native hashmap of
if (!_sectionHashMap.IsCreated)
_sectionHashMap = new NativeHashMap<RegionIndex, EntitySection>(256, Allocator.Temp);
var ecb = new EntityCommandBuffer(Allocator.Temp);
_query = SystemAPI.QueryBuilder().WithAll<LocalToWorld>().WithAny<MaterialMeshInfo, PhysicsCollider>()
.WithNone<KinematicCharacterBody, SkipSceneStreaming>().Build();
var transforms = _query.ToComponentDataArray<LocalToWorld>(Allocator.Temp);
var entities = _query.ToEntityArray(Allocator.Temp);
//Query for entities that have local transform component
for (int i = 0; i < entities.Length; i++)
{
var transform = transforms[i];
var entity = entities[i];
//Define the region that this transform belongs to
var currentRegion = new RegionIndex(transform.Position, 100);
//Create section entity if doesn't exist
if (!_sectionHashMap.TryGetValue(currentRegion, out var sectionEntity))
{
sectionEntity.Index = _sectionHashMap.Count + 1;
//create scene section
sectionEntity.SectionEntity = SerializeUtility.GetSceneSectionEntity(sectionEntity.Index,
state.EntityManager, ref _sectionQuery);
//Add key and value to the map
_sectionHashMap.Add(currentRegion, sectionEntity);
//Add a position to the current section entity
ecb.AddComponent(sectionEntity.SectionEntity, new LocalTransform()
{
Position = currentRegion.GetRegionCenter()
});
}
// Affect the section to the current entity
var sceneSection = state.EntityManager.GetSharedComponent<SceneSection>(entity);
ecb.AddSharedComponent(entity, new SceneSection
{
SceneGUID = sceneSection.SceneGUID,
Section = sectionEntity.Index
});
}
if (ecb.ShouldPlayback) ecb.Playback(state.EntityManager);
ecb.Dispose();
if (_sectionHashMap.IsCreated)
_sectionHashMap.Dispose();
}
}
Any thoughts on what could be causing the lightmaps to disappear?
Thanks in advance for your help!