Why use keyword "class" in TSubobjectPtr, TSubclassOf and in function parameters?

This Use of Class is Extremely Important

I just did this a few moments ago!

This special use of class as a forward declaration is extremely important!

It’s way more concise than forward declaring at the top of your .h file

Consider the following code which I wrote for a project just a few moments ago. This code below is in my highest level class structure, where the actual Actor class being used has not yet been defined.



USTRUCT(BlueprintType)
struct FGalaxyWeapon
{
	GENERATED_USTRUCT_BODY()
 
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Galaxy")
	TEnumAsByte<EGalaxyWeapons::Type> Type;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Galaxy")
	FName SocketName; 
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Galaxy")
	USkeletalMesh* Mesh; 
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Galaxy")
	TSubclassOf<class AGalaxyPickupWeapon> PickupClass;
	
	FGalaxyWeapon()
	{
		//etc
	}
};


For newcomers to the thread, we’re talking about this line:



UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Galaxy")
TSubclassOf<**class** AGalaxyPickupWeapon> PickupClass;


If I did not include class, the above code would throw a compile error because the AActor class is much further along in the compilation process and has not yet been defined.

Yes you could use a forward declaration the way I describe in my wiki, but this method is more concise

Enjoy!

Rama