#Deleting multiple entities with a ghost presentation game object

1 messages · Page 1 of 1 (latest)

rocky iron
#

I'm using the GhostPresentationGameObjectAuthoring to spawn game object for my ghosts on all clients. If i delete multiple ghost entities on the server at the same time, I'm getting multiple exceptions from the GhostPresentationGameObjectSystem. First i get this error for each entity deleted: ObjectDisposedException: Attempted to access ComponentLookup<Unity.NetCode.Hybrid.GhostPresentationGameObjectState> which has been invalidated by a structural change.

Followed by two IndexOutOfRangeExceptions:

IndexOutOfRangeException: Index 0 is out of range in container of '0' Length.

and

IndexOutOfRangeException: Index (0) is out of range TransformAccessArray.Length (0)

the last one is thrown each frame.

I have a minimal example project setup to reproduce this issue. I can attach the full stack trace as an additional message if need be (didn't include the full stack trace to not bloat the initial post too much).

I assume this is a bug or is there another 'intended way' of deleting ghosts with a ghost presentation game object that won't cause these exceptions?

signal lion
#

First error - You are not updated component lookup before doing anything with it

#

hmm, I assume it's not your system?

rocky iron
signal lion
#

how exactly do you destroy your ghosts?

rocky iron
#

with EntityCommandBuffer.ParallelWriter.DestroyEntity() in the EndSimulationCommandBuffer on the server

rocky iron
#

sadly the same outcome. same goes for the init system group command buffers

iron steeple
#

Hello @rocky iron, I have same issue and cannot figure out what is the problem. How did you solve yours?

Some more info about my case:

  • I have the exact same exceptions like the OP.

  • I also use the GhostPresentationGameObjectAuthoring to spawn the client's GameObjects of the ghosts. The client's GameObject Prefab has the GhostPresentationGameObjectEntityOwner script.

  • I instanciate 2 of these entities. If I destroy them in the same command buffer it throws, if I delete only one it works as expected and the client's gameobject and ClientWorld's entity are both detroyed properly.

iron steeple
#

I found the issues, there are 2 bugs in the GhostPresentationGameObjectSystem. I implemented my own custom ghost presentation based on the original one, fixed the two bugs and all good 🙂

#

Bug 1 is when you destroy the last entity

#

Bug 2 is when you destroy multiple entity on the same frame

rocky iron
#

didn't get the chance to further investigate the issue. my plan was to have another look at it 'soonish'. My original assumption was that it is a bug but the lack of other people reporting it made me think it was an issue of my setup. Did you copy the original GhostPresentationObjectSystem and fixed the bugs or do you roll your own self-written implementation?

iron steeple
#

A bit of both

#

I made it but only client side presentation

#

I skipped the server gameobject prefab as I don't need it

#

I was also sure it was a mistake on my side 😉

#

I found this bug (bug 1)

#

made me think I have to try my own implementation

#

then I found our bug

#

pretty obvious actually

rocky iron
#

did you make a bug report? if not i'll make one so it get's fixed by unity eventually. I already have a minimal sample project to reproduce it

iron steeple
#

nope

#

I can't really, wasted too much time already

#

maybe later yes

#

but not in the next weeks at least

rocky iron
#

sure np. i can make one.

#

what was the fix for this bug? another index issue? didn't get much of a chance to have a look at it

iron steeple
#

line: 138 in GhostPresentationGameObject.cs

#

access the lookup

#

then on line: 150 a structural change occurs

#

if the loop iterates once it works, if it iterates one more time it will throw the exception

#

a simple fix is to smash the structural change in a command buffer

rocky iron
#

thanks a lot. Very kind of you to share your solution so i don't have to 'rediscover' the fix. I'll have a look at an optimized solution when adding the quick fix.

I'll make sure to create a bug report for this issue at the start of next week. Will post the public issue here as soon as it is approved so other people can see that it is already reported.

iron steeple
#

Great, thank you very much

#

No problem, I'm refactoring the system differently to avoid that call inside the loop

#

I can send you my impl when it's done if you like

rocky iron
#

I might take a similar approach. Will have to do some benchmarking to see what runs best for my usecase.

rocky iron
iron steeple
#

yup

#

as I said it's client side only

#

I'll post the files here when it's done

rocky iron
#

should be fine. mine's probably gonna support both but should still be interesting to see how it performs and adapting it to client+server support should be that much work (famous last words).

rocky iron
iron steeple
#

should be quite "quick" yes

#

😉

iron steeple
#

I edited my previous messages accordingly.