I’m wondering if there is a possibility to receive a messages, that would normally be sent to the script in the game object containing the collision object? For many collision objects that should do something when collided I need to create a script for each go to handle the message. Could it be optimized? So I could create one object that has a script and a factory of game objects with just collision objects (and sprites) and that main objects has a table of that factored objects in the script and manipulates them, but also has an ability to read theirs messages to handle collisions of each?
This is unfortunately not possible. Perhaps we could add an option to propagate messages to parent objects or something. I’ve run into the same kind of issue as yours in the past.
Is it possible? It would be great, it would help in many cases regarding optimizing the code, so I could create many factored objects without scripts. Many other things relating manipulating such game objects are currently available, except that message issue. Then I’d like to create an issue to follow up, ok?
It’s possible, but we haven’t thought of the implications. It’s not something that will happen soon I’m afraid.
Ok, then, is there maybe any workaround? The problem is, if I want to spawn huge amounts of such game objects with collision objects and script to handle message I’m having a problems with lack of resources and can’t instantiate any new scripts.
I don’t know your actual use case but this is why I use daabbc native extension. You can use daabbc as a broad-phase collision detection for large amount of entities(if “aabb” collisions enough for your case).
The max instance count is 32765. So your “huge” can’t be larger than that. And you can have script in every that instance.
Yes, I can increase instance max count and see how it would be performant, but I guess handling 1000 or 10000 messages isn’t a good solution from software architecture design, that’s why I’m searching for alternatives.
I’ll give it a try, thanks! How does it solves that problem?
Are all of these objects interacting with each other, or only with a few other objects? If you have hundreds of bullets that only do something when they hit a wall, player, or enemy, then you don’t need a script on the bullets, only on the walls, players, and enemies.
But isn’t what you’re asking for in the initial post the same thing? You’d still be getting this many messages, but in one object instead of many.
You would define colliders with this library instead of in the engine, and then whenever you wanted you would just manually check what is overlapping with what. See here.
That is actually helpful, I didn’t looked at the problem from that perspective! Thanks @ross.grams!
That would probably need to be checked, if there would be any difference in performance, but afaik the design of message dispatching in Defold is dependent on number of scripts to send a message to, but correct me, if I’m wrong
It is not using messages and it doesn’t require separate script instance for every collision object. You can just keep ids on a table. It uses box2D’s Dynamic Bounding Volume Hierarchies. So it might fast as box2D (maybe faster) but performance is really depend on your frame update load.