Hi guys, I have created a UWeapon which inherits UObject.
Here is the header:
UENUM(BlueprintType)
namespace EWeaponType
{
enum Type
{
Pistol,
Rifle,
Sniper,
Shotgun,
GranadeLauncher
};
}
UCLASS(Blueprintable)
class TESTINGGROUND_API UWeapon : public UObject
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Weapon")
TEnumAsByte<EWeaponType::Type> WeaponType;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo")
int32 AmmoCapacity;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo")
int32 ClipCapacity;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo")
int32 RemainingAmmo;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo")
int32 AmmoInClip;
/** Projectile class to spawn */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
TSubclassOf<AProjectileBase> ProjectileClass;
UFUNCTION(BlueprintCallable, Category = "Weapon")
void Reload();
UFUNCTION(BlueprintCallable, Category = "Weapon")
int32 AddAmmo(int32 Ammo);
};
And the source file:
UWeapon::UWeapon(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void UWeapon::Reload()
{
if ((this->AmmoInClip < this->ClipCapacity) && (this->RemainingAmmo > 0))
{
int32 AmmoToReload = this->ClipCapacity - this->AmmoInClip;
if (this->RemainingAmmo > AmmoToReload)
{
this->AmmoInClip += AmmoToReload;
this->RemainingAmmo -= AmmoToReload;
}
else
{
this->AmmoInClip += this->RemainingAmmo;
this->RemainingAmmo = 0;
}
}
}
int32 UWeapon::AddAmmo(int32 Ammo)
{
int32 AddedAmount = Ammo;
this->RemainingAmmo += Ammo;
if (this->RemainingAmmo > this->AmmoCapacity)
{
AddedAmount = Ammo - (this->RemainingAmmo - this->AmmoCapacity);
this->RemainingAmmo = this->AmmoCapacity;
}
return AddedAmount;
}
In my character class I have a pointer to a UWeapon defined and initialized in the constructor like this:
// Definition
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon")
TWeakObjectPtr<UWeapon> Rifle;
// Initialize default rifle in the Character's constructor
this->Rifle = NewObject<UWeapon>();
I have also created a Blueprint which inherits UWeapon in order to set the Rifle property of my character. The problem is that the Blueprint is not listed in the dropdown. Can anyone tell why is that?
Here are the pics: