godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

WeakRef has no 'operator=' what makes class unusable.

Open RonYanDaik opened this issue 1 year ago • 5 comments

Godot version

4.1 dev

godot-cpp version

https://github.com/godotengine/godot-cpp/pull/1113

System information

Any

Issue description

C++ class WeakRef has no methods except get_ref() and seems no way to use it in c++. Its missing functions from the engine:

void set_obj(Object *p_object);
void set_ref(const Ref<RefCounted> &p_ref);

Steps to reproduce

n/a

Minimal reproduction project

n/a

RonYanDaik avatar May 30 '23 12:05 RonYanDaik

Thanks!

I haven't tested this, but looking at the code, it appears that UtilityFunctions::weakref() can be used to make a WeakRef.

Does that work for you?

dsnopek avatar May 31 '23 06:05 dsnopek

UtilityFunctions::weakref() Does that work for you?

I've seen it before. but i think it wasn't working. I will test it again. Thank you.

RonYanDaik avatar May 31 '23 09:05 RonYanDaik

UtilityFunctions::weakref() returns a Variant. And WeakRef class has no operator= so it cannot be assigned to a stored WeakRef variable. I feel like having operator= for this class is crucial.

RonYanDaik avatar Jun 23 '23 17:06 RonYanDaik

Are you perhaps using a WeakRef variable instead of Ref<WeakRef>? I just tried the second and it works fine.

EIREXE avatar Jul 27 '23 10:07 EIREXE

Are you perhaps using a WeakRef variable instead of Ref<WeakRef>? I just tried the second and it works fine.

I didn't know about Ref<WeakRef>. Probably because I was expecting something like WeakRef<Object>. Thx. I'll try. I think this needs to be shown in the example project.

RonYanDaik avatar Jul 27 '23 10:07 RonYanDaik