I am trying to make an Overcooked clone as practice and I need some guidance on this problem I’ve been trying to fix for the last few days. This code is in the dispenser box.
What I’m trying to achieve is that when I hit the box, it summons the item, and then puts it in my hands. if I hit it again while holding the item, the item is placed back on top of the box, however, it shouldn’t let me spawn another item.
void AWBDispenserBox::Interact()
{
if(bCanUse)
{
UE_LOG(LogTemp, Warning, TEXT("Dispensing ingredient!~~~"));
const FVector Location = IngredientSpawnPoint->GetComponentLocation();
const FRotator Rotation = GetActorRotation();
AActor* Ingredient = GetWorld()->SpawnActor<AActor>(IngredientsClass, Location, Rotation);
Ingredient->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
Ingredient->AttachToActor(WBCharacter, FAttachmentTransformRules::KeepWorldTransform, "GrabSpot");
bCanUse = false;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Ingredient already on table!"));
}