Multithreading in Defold?

Hi Defold team,

I was just wondering whats the current status of multithreading in Defold? Is proper support for running custom Lua work on background threads planned?

Godot and Unity both support multithreading, and Love2D - which also uses Lua - has thread support as well. I’m curious why this hasn’t been added or prioritized in Defold. Is it mainly due to technical challenges, platform support, API safety, or something else?

I’m especially interested in use cases like pathfinding, procedural generation, and larger AI or simulation workloads, etc.

Native extensions using C++ are an option, but not everyone wants to move part of their game into C++ and maintain all that native code across different platforms. A built-in Lua-friendly solution would be much more approachable.

Thanks!

6 Likes

This is a topic that comes up from time to time. Our recommendation is usually to either write a native extension, like this A* path finding extension, or use a Lua coroutine and divide the computation over many frames.

I think it would be possible to build something very similar to the Love2D Thread system. Such an extension was created a couple of years ago: Experimental Threading extension.

(Today I’d probably look into using the Defold job system instead of going straight for the low level thread API).

1 Like

Defold’s job system works great, by the way. I’ve been using it with Defold Crowd Native Extension for some time now.

3 Likes

Thanks for the reply.

I did see in my search that there are some extensions available for a certain tasks (A* path finding, etc), and there is also Defold’s job system. So, its great that at least there is a way to achieve it, and for experienced programmers who are happy to do some C/C++, they can write their custom logic and get the desired outcome.

My main point is the the barrier of C/C++ and the friction that it creates. Not everyone is proficient in it, not everyone wants to deal with it. When you look at other engines, Godot, Unity, Love2D, using threads is just frictionless and seamless. Which made me wonder, why Defold hasn’t natively added support for multithreading using Lua yet? Is it due to some technical issues? or because of other higher priorities?

People have raised this from time to time as you mentioned as well, and perhaps most of them used some sort of native extension to get the job done. But, is it the high time to consider this feature to be added in Defold engine natively? I don’t know how big of job it would be, but the roadmap for 2027 is just around the corner, perhaps it can be added in that :slight_smile: .

I think it would also be very helpful to have an official document in Defold docs related to the topic of Multithreading, because when you google search, only a few forum posts show up. That document can highlight how multithreading can be achieved in Defold and also some handy extensions.

Personally, I think if it becomes so easy and straightforward to use threads in Defold with Lua, a lot of people will experiment with it, which may lead to some interesting gameplay ideas.

I love Defold, and I love using Lua for game dev in it. The performance is great, build sizes are awesome, and so much going for it. I do some work in Godot as well, but I keep coming back to Defold for most of my projects. Thanks for all the amazing work you do guys!

4 Likes