I want to spawn an Item from my inventory. Only problem is I have no clue on how to make this happen.
/** Items in inventory */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory)
TArray<class AItem*> Inventory;
that’s what I have for my Inventory. I am able to add items in it. Not a problem. but when I want to spawn them, It requires a TSubclassOf. Is there a way to convert my Item class to be a TSubclassOf when casting it?
void ASpecialCharacter::EquipWeapon(AWeapon* Weapon)
{
if (Weapon)
{
FVector Loc = Mesh->GetSocketLocation("Weapon_Socket");
FRotator Rot = Mesh->GetSocketRotation("Weapon_Socket");
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
AWeapon *WeaponSpawn = GetWorld()->SpawnActor<AWeapon>(Weapon,Loc,Rot,SpawnParams); // THIS LINE DOESNT WORK
}
}
this is what I am trying to use to spawn the particular actor(AWeapon is inherited from AItem). and the error I get is it’s telling it cannot convert arguement 1: AWeapon to UClass.
//.h
UPROPERTY(EditDefaultsOnly, Category = Weapon)
class AWeapon* WeaponSelect;
//.cpp
void ASpecialCharacter::OnSelectWeapon()
{
if(WeaponSelect)
{
EquipWeapon(WeaponSelect);
}
}
another thing, I did a simple collision check and made the collision be the WeaponSelect when collided into. But still, gives me the same error.
Anyone have any idea???