Since updating to Entities 0.13, my previously working project now generates many console errors at runtime. Unfortunately, these errors aren’t very descriptive so far, so progress has been slow.
One of the new error messages is this:
ArgumentException: An Entity index is larger than the capacity of the EntityManager. This means the entity was created by a different world or the entity.Index got corrupted or incorrectly assigned and it may not be used on this EntityManager.
So, this error did not occur right before updating to Entities 0.13. And it’s not true that I’m creating any Entities in a different World (I only use one world in my project). The error occurs with and without Burst compilation.
Curiously, if I breakpoint at the line where it says the bad AddComponent() command is recorded, it seems to be passing in a target entity which is correct. It’s also reflected correctly in the Entity Debugger window - i.e. Entity “10:1” is shown as the correct entity that I want to add a component to.
Also, selecting entity 10:1 in the Entity Debugger window will show that the new component has been successfully added to it. Head scratcher.
Any idea what might be causing this? The project worked fine before updating. Could this be a Unity bug?
Thanks for raising this. Can you please file a bug report and attach a reproduction case? Thank you!
Hi,
sorry to bump this thread. I got the same error message with a different setup.
The kontext is different, but for anyone googling this errormessage this is hopefully helpful.
The Message can be misleading, as I found my issue. Perhaps this is linked to the “corruption” part.
Setup:
Entities 0.16.0-preview.21 (but not limited to)
The kontext:
- Creating entities in a temporary world, using entity transaction for getting it in default world.
- Storing the entities in multible persistent
NativeArray<Entity>
with the help of EntityRemapUtility
for later access (up to ~65k)
- At some point these entities are destroyed with
someManager.DestroyEntity(myNativeEntityArray);
- At some point later the array is checked for entities, and they are (tried to) destroyed again.
==>```
ArgumentException: An Entity index is larger than the capacity of the EntityManager. This means the entity was created by a different world or the entity.Index got corrupted or incorrectly assigned and it may not be used on this EntityManager.
Ok, my fault. The entity didn't exist anymore. So a cleanup after destroying the entities solves this for me:
```csharp
someManager.DestroyEntity(myNativeEntityArray);
myNativeEntityArray.Dispose();
myNativeEntityArray= new NativeArray<Entity>(65536, Allocator.Persistent);
At this point the exception is ambigous for me. It was created in a different world, but that’s not the issue. Corrupted? Is a little bit vague and sounds like memory corruption. Incorrectly assigned? No clue, nothing was copied.
In retrospect, however, the message is correct. The entity no longer exists.
TL;DR : This exception can simply be thrown, if an entity index is outside of the capacity of the EntityManager. One additional reason for this could also be, the entity was destroyed.
I hope this helps.
Edit:
I’m now using UnityEngine.Debug.Log messages in an ITriggerEventsJob without the error, so the original post below might be false or misleading.
Original post:
This error arose when I put a UnityEngine.Debug.Log message in an ITriggerEventsJob (without Burst). Removing the Log call fixed it for me.
Code that caused the error for me:
public void Execute(TriggerEvent triggerEvent)
{
Entity entityA = triggerEvent.EntityA;
Entity entityB = triggerEvent.EntityB;
UnityEngine.Debug.Log($"{entityA.Index}, {entityB.Index}");
}
Result:
This is a bit annoying.
I receive this exception in 0.17 with
if (!EntityManager.Exists(entity))
Isn’t the whole point of this method to check if it exists? How do we check if an entity still exists in 0.17?
1 Like