Can't reference to Blueprint based on my class

Hello all,

I made a WeaponBase class, and created a BP based on this class. The class has a property:
“AProjectileType* ProjectileType”. The property needs to be pointing to another BP based on my ProjectileBase class. I want to set this in the editor so its a UPROPERTY(EditAnywhere). The problem i am having is that I am unable to select projectile blueprint in my weapon blueprint, beause it is not listed in the selector. Any ideas?

Tanks a million!!

in WeaponBase.h:

UPROPERTY(EditAnywhere, Category = "Setup")
    class AProjectileBase* ProjectileType;

If I’m understanding what you’re trying to do, you’ll want to use TSubclassOf:

UPROPERTY(EditAnywhere, Category = "Setup")
TSubclassOf<AProjectileBase> ProjectileType;

That allows you to place any class in that slot that is derived from (or is) AProjectileBase.

That did the trick! Thank you so much!

Why is it that if a class if created by me i need to use TSubclassOf, and when it is a class that is already in the engine that is not needed.

e.g.:

UPROPERTY(EditAnywhere)
UStaticMesh* MyStaticMesh;

would work perfectly fine?

UStaticMesh* MyStaticMesh declares a pointer to an object, in this example that reference is as a UStaticMesh instance. The object could be a subclass of that (MyStaticMeshClass or the like), but the pointer will only reference the object as a UStaticMesh, and custom methods or variables native to MyStaticMeshClass wouldn’t be available from it without first casting to MyStaticMeshClass.

TSubclassOf references the class itself, not any particular object instance. You can’t use it directly as an object, you can use it to spawn new objects (or actors) of the held class.

Are you trying to reference the class so you can spawn projectiles of the given type, or are you trying to hold a reference to a specific projectile object?

I am indeed trying to reference the class so i can spawn projectiles of the given type. I am actually trying to do the same thing for my PlayerCharacter with a set of weaponry that need to spawn and attached when selected, and of course then take input (fire, altfire, reload… etc) from the PlayerCharacter. Could you give me a indication if this is the right setup for such an endeavor? I am kinda stuck on this atm :S the following seems not to be allowed:

//PlayerCharacter.h:
UPROPERTY(EditAnywhere, Category = "Weapons")
		TArray<TSubclassOf<AWeaponBase> > Weapons;



//PlayerCharacter.ccp:
AWeaponBase* CurHoldingWeapon;

CurHoldingWeapon = GetWorld()->SpawnActor<Weapons[0].GetClass()>;

Oh this at least get’s rid of the errors…

CurHoldingWeapon = GetWorld()->SpawnActor<AWeaponBase>(Weapons[0]->GetClass());

Just not sure if this can work.

That’s how you want to do it, but you don’t need “GetClass()”, the TSubclassOf is the value you want.

The template value (between the “<>”) can’t be a variable.

Thank you! Happy to build this system with the knowledge that this is not completely wrong ;).