I have multiple items "tanks" and every tank has pinned object "turrent".
Turrents are pinned to tanks.
Tank is main moving object and if I destroy tank object then turrent object remains to screen. How to destroy specific tank turrent?
Read up on Containers
Develop games in your browser. Powerful, performant & highly capable.
In the past I just destroyed all unpinned, it cleaned it all up. (That was before containers)
I still use UIDs instead of containers a lot. I can do stuff like destroy the turret but leave the tank alive for a few seconds before also being destroyed. It takes a little extra effort, but I always end up needing that freedom at some point.
Just make an event that says: 'on tank created > tank spawn turret > set turret variable 'id' to tank 'UID''.
Then: 'on tank destroyed + turret.id = tank.UID: destroy turret'
But really if you are just making something simple, use containers.