TSubClassOf not restricting editor input

Hi everyone,

I am having a problem with extending C++ classes to blueprints, and with TSubClassOf.

I am trying to create an attachment system. I have a base class in C++, UAttachmentBase, inheriting from UObject. I have then created another C++ class inheriting from this, called USightAttachment, with Blueprintable and BlueprintType in the UCLASS macro.

I then created a blueprint inheriting from the USightAttachment class, called DefaultSightAttachment.

I want to be able to select a subclass of USightAttachment from a USTRUCT(BlueprintType) in another class, so I have the following struct definition:

USTRUCT(BlueprintType)
struct FWeaponAttachmentsStruct
{
	GENERATED_BODY()

public:
	//Sight attachment
	UPROPERTY(EditDefaultsOnly, Category = "Weapon Attachments")
		TSubclassOf<USightAttachment> SightAttachment;

};

and I make the struct accessible (along with some other structs) in another blueprint.

However, when assigning the variable in the blueprint, instead of restricting the selection of SightAttachment to just USightAttachment class, it allows all classes.
image

I want to only be able to select USightAttachment classes from this, similar to the system whereby a variable defined as UStaticMesh* and exposed to the blueprint editor will only allow selection of static meshes.

Strangely the TSubClass works with a separate class, AFPSProjectile

UPROPERTY(EditDefaultsOnly, Category = "Projectile")
		TSubclassOf<class AFPSProjectile> ProjectileClass;

image

But this is an actor class, and I am not using an actor class for my attachments. I also tried with the class USightAttachment in the <> but this did not work either.

Any help would be appreciated.

Make sure you have the correct descriptors and macros in your component

UCLASS(Blueprintable, BlueprintType, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class SIGHTCOMP_API USightAttachment : public UObject
{
}

Here is a project showing it in action filtering works as expected.
SightComp.zip (28.3 KB)

Only later noticed you are still on ue4 (this is in 5.1 but you can still look through the source and see how I set it up)

1 Like

Thank you very, very much, it now works!

Also, thanks for all the work you do on this community, this isn’t the first time you have helped me.

1 Like