To be more precise, I mainly use locally spawned then destroyed items every frame when I need to show their icons in a GUI that don't come from any real item. For example, my mortar and pestle GUI is not a real container and only shows ingredients and resulting potion, that not longer exist or does not exist yet. If I had to change this system I could store real items somewhere or again put all items definitions used by the mod in a table...minmay wrote:If you need an object every frame, I'd suggest spawning it once and putting it on a map or in a ContainerItemComponent, instead of spawning and destroying it every frame - you don't save any memory by doing that, and the impact on saving performance by one object (or ten) is vanishingly small.
That's right, adding a sortOffset to my ParticleComponent resolved the problem. In my case, the ParticleComponent belongs to an object with SkyComponent, and the model components have sortOffset fields (same as the original forest sky). Now that the particle also has it the problem is gone for some reason!minmay wrote:I can't reproduce this. For me, that exact situation works perfectly. Are you sure you aren't doing something weird with sortOffset and/or depth bias? For that matter, you may be able to use sortOffset to fix it (I'm not sure exactly how it works w/r/t particles, it might only be relevant for triangles/particles that are coplanar and intersecting...).
Hooks on the SurfaceComponent, onInsertItem and onRemoveItem? In that case, no I certainly don't use it. If you talk about hooks on items, I cannot predict it, any item in an inventory could be placed in my object if the player decides to dismiss a champion. Also, when I considered the ConainerItemComponent option, I found 2 problems; can we get any capacity? (32 slots needed to store a full inventory)? What about containers in that inventory that don't fit in other containers?minmay wrote:It's the same problem with destroying the ItemComponent: the re-created SurfaceComponent won't have any hooks. Of course it will be fine if you don't use hooks.
It sounds like ContainerItemComponent would work better for this since you wouldn't have to add the object to the map at all in the process.
Edit : could I use setPosition to put an object with no map on a map, then destroy it to collect the garbage?