What is a "weak object pointer"?

Jumping from doc to doc, I bumped in this statement:

“Automatic version of the weak object pointer”, referring to “TWeakObjectPtr”

It’s nothing really important, but I like to know what exactly is a “weak object pointer”

This might help you: What's the difference between using TWeakObjectPtr or using UObject* - Community & Industry Discussion - Unreal Engine Forums

So basically there is no big difference between normal pointer and TAutoWeakObjectPtr?

Normally, i use this for pointer of an actor which might be destroyed, so when this actor being destroyed, pointer won’t prevent the actor to be destroyed, causing crash sometimes. But this one is equivalent to UPROPERTY(), so most of the time i use UPROPERTY() instead of TWeakObjectPtr.

So what happens if the object gets destroyed? I mean, with a normal pointer I would check everytime if (pointer != nullptr), what about this kind of pointer? I am a bit confused about destruction: when the object is destroyed pointer != nullptr will return true even if the object has been destroyed whilst IsValid() will return false?

There is a big difference: A normal pointer doesn’t know when the pointed-to object has been destroyed, while a weak pointer does. A normal pointer is only safe to access if you can guarantee that the object is still valid.

With a smart pointer (such as TSharedPtr), pointer != nullptr would indicate that the object was safe to access because the pointer was itself keeping the object alive. With a normal (raw) pointer, pointer != nullptr would return true even after the object was destroyed; this check would not be sufficient to avoid crashes. With a weak pointer like this, the pointer itself becomes null and invalid once the object is destroyed. This behavior (suddenly being null, when it wasn’t null before) is unique to weak pointers. No other pointer type does that.

Ok, I got it. One last question: Duncan in the comment above said that using the UPROPERTY macro you can achieve the same result, that means that a pointer marked as uproperty is set to null when the object it’s pointing to is destroy, am I right?

Almost, but not exactly. UObject (or, more commonly, UObject-derived) pointers with UPROPERTY() annotations behave as strong pointers – that is, they will keep the object alive even when nothing else refers to it. The tricky bit is, if the UObject is explicitly Destroy()ed (as opposed to being garbage collected), such a pointer will be nulled. So you can think of UPROPERTY pointers as “strong, but Destroy() is stronger”.