(Case 1319764) Adding/removing components or changing position/rotation/velocity/collide

After updating to Unity 202.2.7f1 and the packages


I now get two new exceptions. It could be the code was buggy always and now an integrity check has been added that throws, however it it is pretty annoying as the stack trace does not link to my code at all…

[Exception] InvalidOperationException: The BlobAssetReference is null.
BlobAssetReferenceData.ValidateNotNull() at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/Blobs.cs:275
273:   {
274:       if(m_Ptr == null)
-->275:           throw new InvalidOperationException("The BlobAssetReference is null.");
277:       ValidateNonBurst();

Unity.Entities.BlobAssetReference`1[T].get_Value() at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/Blobs.cs:365
363:   get
364:   {
-->365:       m_data.ValidateNotNull();
366:       return ref UnsafeUtility.AsRef<T>(m_data.m_Ptr);
367:   }

ExportPhysicsWorld.CheckColliderFilterIntegrity() at Library/PackageCache/com.unity.physics@0.6.0-preview.3/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs:307
305:   {
306:       var collider = colliders[i];
-->307:       if (collider.Value.Value.Type == ColliderType.Compound)
308:       {
309:           unsafe

ExportPhysicsWorld+CheckColliderIntegrity.Execute() at Library/PackageCache/com.unity.physics@0.6.0-preview.3/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs:271
270:           var colliders = batchInChunk.GetNativeArray(PhysicsColliderType);
-->271:           CheckColliderFilterIntegrity(colliders);
272:       }
273:   }

Unity.Entities.JobEntityBatchExtensions+JobEntityBatchProducer`1[T].ExecuteInternal() at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/IJobEntityBatch.cs:571
569:           var batch = new ArchetypeChunk(chunk, chunks.EntityComponentStore);
570:           Assert.AreNotEqual(0, batch.Count);
-->571:           jobWrapper.JobData.Execute(batch, batchIndex);
572:       }
573:   }

Unity.Entities.JobEntityBatchExtensions+JobEntityBatchProducer`1[T].Execute() at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/IJobEntityBatch.cs:513
511:       int jobIndex)
512:   {
-->513:       ExecuteInternal(ref jobWrapper, bufferRangePatchData, ref ranges, jobIndex);
514:   }
[Exception] InvalidOperationException: Adding/removing components or changing position/rotation/velocity/collider ECS data on dynamic entities during physics step
SafetyChecks.ThrowInvalidOperationException() at Library/PackageCache/com.unity.physics@0.6.0-preview.3/Unity.Physics/Extensions/SafetyChecks.cs:164
163:   [Conditional(ConditionalSymbol)]
-->164:   public static void ThrowInvalidOperationException(FixedString128 message = default) => throw new InvalidOperationException($"{message}");
166:   [Conditional(ConditionalSymbol)]

ExportPhysicsWorld+CheckTotalIntegrity.Execute() at Library/PackageCache/com.unity.physics@0.6.0-preview.3/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs:294
292:   if (!validIntegrity)
293:   {
-->294:       SafetyChecks.ThrowInvalidOperationException("Adding/removing components or changing position/rotation/velocity/collider ECS data" +
295:           " on dynamic entities during physics step");
296:   }

Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute() at <42a5878ce129403083acccf18e43363f>:0

There’s a lot more safety in newer entities (and especially 2020.2+). We found tons of bugs in old code because of this.

It should be some code of yours running in FixedUpdate since it’s happening during physics. You’re probably just missing a handle and/or updating between physics steps instead of before/after.

1 Like

Might relate to: (Case 1325061) 2020.3.0f1 ExportPhysicsSystem throws Invalid Operation .

Separated the threads as I was able to pinpoint the BlobAssetReference: null being caused by an Archetype having a PhysicsCollider (which I would expect to be valid?).