Download

Can garbage collection still delete an object reference even if it is marked with the uproperty reflection macro

Hi, I’m actually not sure if the problem I have is due to garbage collection or not but, in my code I create a widget and then assign it to a variable(* pointer) and seem like everything is good I check for isvalid and call methods inside the object, everything works, but the problem is that it will just work there, if I call it at a later point it suddenly becomes a nullptr, I have marked it as uproperty, but can garbage collection still collect it even though it has not been marked as being destroyed.

I have a picture that maybe makes easier to understand.
Screenshot_1

No. Not unless someone is manually marking it as pending kill. If your MainInventoryWidgetRef is:

UPROPERTY()
MainInventoryClassRef* MainInventoryWidgetRef;

And not using a TWeakObjPtr or anything like that, it should keep the reference valid and prevent GC.

thanks for answering, yes I had defined it exactly like that, maybe I did something wrong somewhere I don’t know, but it’s’ weird because it worked before but I had to change the code alittle bit, and what I did was to just not creating it the first time you press the button to open the widget, but rather in the onposess method.

The weird part is that I have never created any destroy method, cause it’s supposed to be there until the match ends and another map loads.

this is how it’s set up in the header, maininventoryclassref is set in the child blueprint class
Screenshot_2

So another thing is to make sure whatever Object contains these references is properly being tracked (I assume it’s your Player - which should be kept valid by the World when you spawn in).

Hi, it seem maybe it’s that problem, I’m checking visual studio debug and the pawnref I have in player controller also is null, maybe passing around pawn refs is not a good idea. Thank you, I’m gonna try just casting instead when it’s needed, see if that fixes the problem

Hi, I found the problem, it wasn’t the widget reference that was the problem, but the controller reference, I used kismet getplayercontroller instead and it worked, doesn’t seem like getcontroller works for multiplayer games, putting it here in case someone runs into something similar, thanks for helping