Hello.
I’ve a Pickup actor class. When the character takes the pickup it has to disappear and reappear after a certain ammount of time.
When the pickup mesh is taken, this function gets called:
void APickup::OnPickup(AActor* OtherActor)
{
if (bIsActive)
{
// Disable the pickup
bIsActive = false;
if(GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("PICKUP PICKED!"));
// Play the pickup sound (should be heard only by he who takes the item!)
UGameplayStatics::PlaySoundAtLocation(this, PickupSound, GetActorLocation());
// Hide Pickup and trigger respawn timer
SetActorHiddenInGame(true);
GetWorldTimerManager().SetTimer(RespawnTimer, this, &APickup::Respawn, RespawnDelay, false);
}
}
The bIsActive means: if the pickup has already been taken, well, we don’t want the player to take it the same.
RespawnTimer is a FTimerHandle
RespawnDelay is a float and represents the ammount of time needed before respawning the item into the world
After [respawndelay] seconds, I should see my Respawn() function got called… but that doesn’t happen
respawn function:
void APickup::Respawn()
{
if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("PICKUP RESPAWNED!"));
SetActorHiddenInGame(false);
bIsActive = true;
}
All this function does is resetting the visibility of the item through SetActorHiddenInGame(false); and setting the bIsActive variable again to true
Once I pickup the item, the OnPickup function gets called, but after %RespawnDelay seconds, I don’t see it reappearing.
NOTE THAT: if I delete bIsActive = false; from the first piece of code (and so in the OnPickup() function), the Respawn() function gets called.
Help!