Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Karvalho | |
Old Version | Published before Godot 3 was released. |
How can I instantiate Vector2 and Dictionary in C++, and use Vector2 as keys in that dictionary?
I’ve tried this:
//MyMod.h
#include "dictionary.h"
#include "math_2d.h"
//MyMod.cpp
Dictionary dict = memnew(Dictionary);
Vector2* v = memnew(Vector2(1, 1));
dict[v] = 10;
return dict;
It compiles successfully, but inside Godot there’s no key Vector2(1, 1):
#Test.gd
var myMod = MyMod.new()
var dict = myMod.getDict()
print(dict[Vector2(1, 1)])
Returns an error: Invalid get index ‘1,1’
But this works:
//MyMod.cpp
Dictionary dict = memnew(Dictionary);
dict[1] = 10;
return dict;
and
#Test.gd
var myMod = MyMod.new()
var dict = myMod.getDict()
print(dict[1])
It prints 10, as expected.
So I’m obviously instancing Vector2 wrong. Or am I not?