Sorry, I totally forgot about this thread in the wave of other posts! :sweat_smile:
If I had to guess, the issue is probably that nothing is holding a reference to the object, so as soon as the _ready
function is called and finished, the reference counter see that nothing is holding a reference and then deletes the object.
I'd try making a private variable to hold the TestReference class. Then when you make a new reference, you can assign it to that variable and it should stick around as long as its being held by the variable. In GDScript, it would look something like this (for example):
var stored_ref
func _ready():
stored_ref = test_ref.new()
While in C++ you'd need to add something like private TestReference stored_ref;
in the header file and the you can do something like this in the source:
void GDExample:test_sth() {
stored_ref = TestReference::_new()
// Other code here
}