I am wondering if it is best to destroy entities at a certain time in the cycle because I am receiving an error once in a while when an entity is destroyed:
IndexOutOfRangeException: Index 6 is out of range of '6' Length.
Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <bb4ed9929fe04849bbe2b059cba4d31f>:0)
Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <bb4ed9929fe04849bbe2b059cba4d31f>:0)
Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <bb4ed9929fe04849bbe2b059cba4d31f>:0)
Unity.Rendering.SimpleCullingJob.Execute (Unity.Entities.ArchetypeChunk archetypeChunk, System.Int32 chunkIndex, System.Int32 firstEntityIndex) (at Library/PackageCache/com.unity.rendering.hybrid@0.10.0-preview.21/Unity.Rendering.Hybrid/HybridV2Culling.cs:344)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].ExecuteInternal (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.16.0-preview.21/Unity.Entities/IJobChunk.cs:370)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].Execute (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.16.0-preview.21/Unity.Entities/IJobChunk.cs:337)
any idea what might help with this error? It happens on the frame that I destroy an entity.
Unless you are doing some sort of structural change inside of PresentationSystemGroup between bounds updates and rendering, this looks like a Hybrid Renderer bug.
Its a bug in HybridCullingV2, I mentioned a fix in the Hybrid Renderer thread.
The graceDistance features allows batches to go out of date as they are not refreshed when an entity is deleted.
I simply turned off the graceDistance feature of the LOD culling and all the glitchy issues with LODs (having to move camera to get updates) and that crash goes away.
LIne 155 of HybridV2Culling.cs
float graceDistance = 0.0f;
This generally only causes a crash when you move the camera backwards, which never happened in Megacity, which is how this crash is still here.
/*
* This culling approach oriented from Megacity and works well for relatively
* slow-moving cameras in a large, dense environment.
*
* The primary CPU costs involved in culling all the chunks of mesh instances
* in megacity is touching the chunks of memory. A naive culling approach would
* look like this:
...
* - Because the camera moves relatively slowly, we can compute a grace
* distance which the camera has to move (in any direction) before the LOD
* selection would compute a different result
*/
If you delete an entity before the grace distance is up the culling crashes because the entity doesnt exist any more. If you are moving forward it never happens because the deleted entity chunk is culled in its entirety.