Pickup doesn't respawn

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!

Is this a bug?

bIsActive is your varable?

Yes it’s a variable I made to determine whether the pickup has been taken or not

It’s a strange behavior though. What should I do?

It looks ok to me, do you use bIsActive somewhere else?

It’s just an EditAnywhere boolean UPROPERTY that I set to TRUE in the Editor for that particular pickup instance.

Do you set bIsActive to true in constructor?

No. It’s only editable in the Editor

Then try setting bIsActive = true in constructor and try not touching in in editor for the try

And again do you use bIsActive somewhere else then code pasted (and constructor)?

“Then try setting bIsActive = true in constructor and try not touching in in editor for the try”

Done. Still no luck =(

I don’t use the variable anywhere else

Ok then i don’t know. Try to trace it out with debuging, put break point on " if (bIsActive)" and step by step see when it executes SetTimer and overall state of bIsActive

I am so stupid.

I don’t know why, in the Tick event there was this code:

if (!bIsActive)
{
	SetActorHiddenInGame(true);
	GetWorldTimerManager().SetTimer(RespawnTimer, this, &APickup::Respawn, RespawnDelay, false);
}