Currently, TWeakObjectPtr does not support forward declarations, which can be a bit of a nightmare when creating custom structs that you want to reuse. For example:
// This is a header file included by all classes in the game, container a series of enums, structs etc. Similar to Shootergame.
GESTypes.h
USTRUCT(BlueprintType)
struct FMissionTarget
{
GENERATED_USTRUCT_BODY()
// Component we're targeting
UPROPERTY(BlueprintReadOnly, Category = "Target")
TWeakObjectPtr<USceneComponent> TargetComponent;
// Socket on the component we're targeting
UPROPERTY(BlueprintReadOnly, Category = "Target")
FName TargetSocket;
// ID of the mission this target belongs to
UPROPERTY(BlueprintReadOnly, Category = "Target")
int32 TargetMissionID;
// Cached Pointer to the Mission
UPROPERTY()
TWeakObjectPtr<const UActiveMission> TargetMissionPtr;
FMissionTarget()
: TargetComponent(NULL)
, TargetSocket(NAME_None)
, TargetMissionID(-1)
, TargetMissionPtr(nullptr)
{}
};
The above code does not allow compilation to occur, because it doesnât know what âUActiveMissionâ is (which is a custom UObject class). Using a forward declaration
TWeakObjectPtr<const class UActiveMission> TargetMissionPtr;
still prevents compilation, because it canât determine the template type as a UObject.
UActiveMission already includes this file and needs to do so, which makes compilation impossible and creates circular dependencies.