0 votes


I am new to Godot. I am aiming to create a RTS game with 10's of thousands of units and for it to run smoothly. So I'm looking to use GDNative C++ with the Visual Server to handle updating and moving the units and GDScript for everything else.

The following script in GDScript successfully renders a single multi mesh cube at the center of the screen.

extends Spatial

func _ready():
    var meshRid=preload('res://new_cubemesh.tres').get_rid()
    var multimesh = VisualServer.multimesh_create()
    VisualServer.multimesh_allocate(multimesh, 1, VisualServer.MULTIMESH_TRANSFORM_3D, VisualServer.MULTIMESH_COLOR_NONE, VisualServer.MULTIMESH_CUSTOM_DATA_FLOAT)
    VisualServer.multimesh_set_mesh(multimesh, meshRid)
    var instance = VisualServer.instance_create()
    var scenario = get_world().scenario
    VisualServer.instance_set_scenario(instance, scenario)
    VisualServer.instance_set_base(instance, multimesh)

I have implemented the alternative In GDNative (C++) and while it doesn't crash and does run the code, it does not render the cube. Camera is in correct position to observe the cube at 0,0. I've just re-purposed the GDNative C++ tutorial for now.

I really like the community here and the engine so far, so hopefully I am just misunderstanding something here and it is possible what I am trying to achieve.

Thank you for your time, c++ scripts below.


#include "gdexample.h"

using namespace godot;

void GDExample::_register_methods() {
    register_method("_process", &GDExample::_process);
    register_method("_ready", &GDExample::_ready);

GDExample::GDExample() {

GDExample::~GDExample() {
    // add your cleanup here

void GDExample::_init() {
    // initialize any variables here

void GDExample::_ready(){

    visual = visual->get_singleton();
    loader = loader->get_singleton();

    Ref<Resource> meshResource = loader->load("res://new_cubemesh.tres");
    RID meshRid = meshResource->get_rid();

    multimesh = visual->multimesh_create();
    visual->multimesh_allocate(multimesh, 1, visual->MULTIMESH_TRANSFORM_3D, visual->MULTIMESH_COLOR_NONE, visual->MULTIMESH_CUSTOM_DATA_FLOAT);
    visual->multimesh_set_mesh(multimesh, meshRid);

    RID instance = visual->instance_create();

    Ref<World> world = get_world();
    RID scenario = world->get_scenario();

    visual->instance_set_scenario(instance, scenario);
    visual->instance_set_base(instance, multimesh);


Let me know if you need gdexample.h or gdlibrary.cpp and I can add, the formatting gets messed up if I include them here for some reason. It's basically just the tutorial stuff though.

Godot version Godot Engine v3.2.3.stable.official
in Engine by (12 points)
edited by

Please log in or register to answer this question.

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.