Before we begin
In this class, we will use a new smart pointer type. TObjectPtr<>
is the Unreal Engine 5 standard way of dealing with components held on an actor. The prior standard was to use raw pointers, but this will no longer work with the new garbage collector, as the new system provides reference tracking to detect when an object is actually used. This can mean that objects only stored in raw pointers get mistaken for de-referenced memory and can be deleted while still in use.
Within functions, we will still use raw pointers, as these variables will go out of scope, and so the garbage collector is not necessary to free their memory. Member variable object references will be stored as TObjectPtr<>
and asset references stored as TSoftObjectPtr<>
.