mkrebser / GPUInstance

Instancing & Animation library for Unity3D
Other
228 stars 44 forks source link

"Tried to parent a child to an unitialized parent" error on a parent that's already been initialized multiple frames ago. #15

Closed projectBreakableAccAPI closed 11 months ago

projectBreakableAccAPI commented 11 months ago

I know for a fact that the instance was initialized because I literally see it, and when trying to initialize it again, I get the "already initialized" error. I also know the parentID is 1 on every instance parented at startup, and that I'm inputting 1 to the new instances, so it's not that. Is there something I'm doing wrong? How do I parent new instances to an old instance? Sorry if this is another case of me missing it in the code guide or something, but I'm pretty lost.

Thank you once again, Max

projectBreakableAccAPI commented 11 months ago

So I did a bit more testing and found out that after initializing the set, the parent is set not to the parent who's id I originally assigned, instance 0, but to the ID of the Instance at index 0 in the set being initialized. Why? Do I really have to set the parent to 0 after initializing the set every time, or is there some flag I'm oblivious to?

mkrebser commented 11 months ago

That function works on the indices of the array

https://github.com/mkrebser/GPUInstance/blob/master/Assets/Resources/GPUInstance/scripts/MeshInstancer.cs#L287-L294

It assumes every item in the array is uninitialized and using array index as parent since an uninitialized item does not yet have an ID

projectBreakableAccAPI commented 11 months ago

Got it, thank you for updating the documentation and for your help :)