This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So I have been working on a Project for quite some time. In the interest of improving performance, I decided to look into GDNative and alike, but found some stumbling stones (things that I do not understand).

I am unsure how it would be possible to use "draw_line" for example.
Now this might be, because I do not know enough about c++ to figure out on my own, but let me give an example:

TestDLL.cpp

#include "TestDLL.h" 
using namespace godot;


void TestDLL::_register_methods() {
    register_method("_process", &TestDLL::_process);
    register_method("_draw", &TestDLL::_draw);
}

void TestDLL::_init() {

}

void TestDLL::_process(float delta)
{
    _draw();
}

void TestDLL::_draw()
{
    CanvasItem::draw_line(Vector2(200, 100), Vector2(200, 1000), Color(255, 255, 255, 1), 1);
}

TestDLL.h

#pragma once

#include <Godot.hpp>
#include <Node.hpp>
#include <CanvasItem.hpp>

namespace godot {
    class TestDLL : public Node
    {

    private:
        GODOT_CLASS(TestDLL, Node)
    public:
        static void _register_methods();
        void _init();
        void _process(float delta);
        void _draw();

    };

}

The code will not compile since it detects an error with "CanvasItem::draw_line" which says: "a nonstatic member reference must be relative to a specific object"

The biggest problem here is that I have no clue where to go from here, or if what I have written would even work, without this error.

Any suggestion are appreciated, though if someone could show me a more generalized guide on how to use c++ in this context that might be even more helpful. Thanks! :)

in Engine by (14 points)

1 Answer

+1 vote

Error "a nonstatic member reference must be relative to a specific object" means that draw_line() is not a static function so you need to create an instance of the class CanvasItem first.

Try this:

CanvasItem canvasItem;
canvasItem.draw_line(....);
by (44 points)

Thank you very much! It resolved the problem perfectly!

Ok I need to correct myself a little bit.
The solution worked for the problems I had with building the dll File.
Today I actually applied it to godot with a GDNative-Library.
There nothing showed up. No Error, no message, nothing.
So I played around with the Code a little bit and turns out to call drawline(), you do not need any object at all.
So in the _draw() function I just wrote the draw
line(...) Stuff, and it actually worked! Awesome!

Ahh! I see. I haven't worked in GDNative, my answer was purely on the basis of the c++ error that you got. Glad it worked out for you!

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.