Enjoying a bit of Defold time at the moment, which is a luxury!
I bumped into an issue recently that took me a while to figure out. This is the flow:
Monarch shows a screen with a trigger collector collision object.
The scene spawns collision objects with collectionfactory.create() and references to these objects are stored in a module.
When the collector collision object touches a spawned object, it deletes it IF there is a matching reference in the module.
Once all objects have been removed, the screen reloads.
The issue: After a few reloads the collision object starts returning game object ids that don’t match the ones in the module. The reference name is something like hash: [/collection94/collisionobject] and the collision object returns something like hash: [<unknown:3844889965836164311>].
Now, after a lot of troubleshooting, I realised that if collectgarbage() is called before spawning the collections, the collision object returns the correct id! See minimal project and vid below.
There are no errors in the console when the “unknown” ids are returned. Is this expected behaviour? Should I start taking garbage collection more seriously?
The reason I need to be able to match the id returned by the collision object with the module is because I’m using this method to circumvent the 16 collision group limit in box2d. On creation I can assign any arbitrary data to the objects, for example “this is a spike”, “this is a coin” and keep the same collision group id for all collision objects.