The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Can 3D objects/meshes be imported/loaded by code from within the running game, or would I have to write my own addon to accomplish this? To be clear, I'm not talking about instantiating a saved scene, but importing a 3d model/mesh from within the game.
I'm developing my infrastructure for an upcoming project and I want the player to be able to mod in-game objects. For example, you might have a drag race simulator and allow the players to design their own 3D car bodies (in Blender) and use them to design their in-game car. And btw, at this stage, I'm not concerned about the security of mods or the problems mods can cause, just possibilities :) Thanks in advance.

in Engine by (318 points)

2 Answers

+1 vote

Yes, you can! Something like this should do the trick:

var cubemesh=load('res://cube.msh')
where cube.msh is whatever mesh the user wants to import.

If you want to give it a collider, do the previous from a RigidBody, then do this:
For your application, it sounds like you want to use ConvexPolygonShape or ConcavePolygonShape rather than BoxShape though.

by (56 points)

Thanks for the reply. That is pretty much what I want, but my problem is the .msh file. It is the only file format that I see to define the shape of custom meshes in Godot and it’s created by importing an .obj file in the editor during development. I don’t see any way to either get an .obj into the finished game on the fly, or any way to create an .msh file outside of the Godot editor.

Did you solve this Michael Paul? Or is there really no way to import .obj files for later modding etc?

0 votes

For load directly an .obj

    var meshInstance =
    var mesh = load("res://file.obj")
    call_deferred("add_child", meshInstance)


by (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.