C++ NativeScript version not rendering multimesh instance whereas GDScript version does

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By colourfit

Hello.

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.

gdexample.cpp

#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
	base=5;
}

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.