How to use methods from GDScript class in GDNative C++ ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DriNeo
:warning: Old Version Published before Godot 3 was released.

Hello. I try to translate the bunnymark scripts into binary scripts using GDNative but I’m stucked on the the preload function. I don’t know which file to include to the cpp file.
Any information is welcome.

:bust_in_silhouette: Reply From: Zylann

preload is a GDScript feature, which basically calls load behind the scenes when the game starts. You won’t find the exact equivalent in GDNative, which is C/C++. However, you can load resources by including <godot_cpp/ResourceLoader.hpp> and calling ResourceLoader::load("resource path"), which returns a Resource that you can cast to the resource type you need (see Object method for checking if the type is correct before casting).

On a personal note, while I understand it’s for having an example of the bunnymark project in C++, I would advise against hardcoding resource paths in a GDNative library (and prefer GDScript or properties for this data/high-level stuff), unless you really want to only use C++ as your scripting language :slight_smile:

C++ will be the only scripting language in this project but this is a project for testing (and for fun) only . Thanks for the advice.

DriNeo | 2017-04-21 21:25