godot: GDextension C++ bug Dictionary PROPERTY, variable in editor

Tested versions

Godot engine 4.2 stable

Captura de pantalla 2023-12-06 132243

System information

windows 11, intel i5 10ma, rx 6600 xt,godot 4.2 stable

Issue description

When exposing a dictionary in the editor with C++ GDextension, the dictionary is reset every time you exit the node, you cannot add more keys either. That is, if you add more keys or add data, when you reload the property is deleted and it remains as if it had not been modified

Steps to reproduce

Captura de pantalla 2023-12-06 133551

https://www.youtube.com/watch?v=dEY7l8SMW18

creates a dictionary with its corresponding get and set and then adds the property to the editor.

.h

  public:
      Dictionary sounds;

        // Getter para la propiedad 'sounds'
        Dictionary get_sounds() const;

        // Setter para la propiedad 'sounds'
        void set_sounds(Dictionary value);

.CPP

//property editor binding method
ClassDB::bind_method(D_METHOD("get_sounds"), &Zombie::get_health);
ClassDB::bind_method(D_METHOD("set_sounds", "sounds"), &Zombie::set_health);
ClassDB::add_property("Zombie", PropertyInfo(Variant::DICTIONARY, "sounds"), "set_sounds", "get_sounds");
// Getter para la propiedad 'sound'
Dictionary Zombie::get_sounds() const
{
	return sounds;
}

// Setter para la propiedad 'health'
void Zombie::set_sounds(Dictionary value)
{
	sounds = sounds;
}

Minimal reproduction project (MRP)

open the zombie scene and see the scene root that was inherited from the gdextension Zombie class. There is the Dictionary property that gives an error when modifying its value from the editor.

The following project opens with visual studio 2022 and has the static libraries preconfigured, you just have to press F5 if you have installed correctly what the repository says.

https://gitlab.com/kone9/visual-studio-godot-engine-gdextension-cpp-template/-/tree/Godot_4_2_ZOMBIE?ref_type=heads

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

If you have suggestions please open them here 🙂

The documentation for GDExtension is lacking and work is being done on improving it

ok, I’m going to do them… at least the one where you don’t have to restart the editor every time you add a property. Thank you so much.

These are all very different questions, I’d suggest reading the documentation and asking on the other channels, most of this sounds like support questions, don’t see any bugs from what you’re describing

For the packed scene you should do: PropertyInfo(Variant::OBJECT, "...", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), see here

Yes, they are actually suggestions. Not bugs.

The only thing I do take as a bug is that every time you generate a property or want to reference a signal in GDextension C++ you have to restart the editor and that is a lot of waste of time.

I’ll try what he told me I also did not find documentation on how to use packet scene with GDextension c++.

I also want to say that I used GDnative C++ before and now it is much more confusing to register a property.

Thank you very much for answering,

ClassDB::bind_method(D_METHOD(“get_sounds”), &Zombie::get_sounds); ClassDB::bind_method(D_METHOD(“set_sounds”, “sounds”), &Zombie::set_sounds);

The error continues, but now only when I choose another node

This is not a bug and I can confirm the correct code works, for support questions and help please first turn to the other community channels, this is for bug reporting, not a help desk. Please use other channels first to see if this is a bug or user error.

Please try and make sure your code is in basic working order before making a bug report, asking in other channels

Ok, yes you are right. Now it works. It’s a bit confusing to register the property and I accidentally put in the wrong code. It is still rare that all properties are broken because of just one poorly written one. To take that into account. Thank you so much.

video showing the correct operation of dictionaries with GDextension. https://www.youtube.com/watch?v=PCXieycqWXc