# Calling destroy self c++ function from BP causes short freeze first time only

**URL:** <https://forums.unrealengine.com/t/calling-destroy-self-c-function-from-bp-causes-short-freeze-first-time-only/452411>\
**Category:** Blueprint\
**Tags:** Destroy-Actor, unreal-engine, Blueprint, question, CPP, calls\
**Created:** [July 17, 2019, 2:53pm UTC](https://forums.unrealengine.com/t/calling-destroy-self-c-function-from-bp-causes-short-freeze-first-time-only/452411 "2019-07-17T14:53:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bridgeburners](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bridgeburners](https://forums.unrealengine.com/u/Bridgeburners)\
**Post date:** [July 17, 2019, 2:53pm UTC](https://forums.unrealengine.com/t/calling-destroy-self-c-function-from-bp-causes-short-freeze-first-time-only/452411/1 "2019-07-17T14:53:15Z")

</div>

Suppose we have the following Blueprint Callable c++ function in MyGameState:

```
void AMyGameState::DestroySubactor(ASubactor* Subactor) {
    if (IsValid(Subactor)) Subactor->Destroy();
}

```

Suppose as well that a Blueprint child class of Subactor, called “SubActorBP”, has a blueprint function called “DestroySelf” which essentially does the Blueprint-equivalent of the following code:

```
void ASubactorBP::DestroySelf() {
    AMyGameState* CastedGameState = Cast<AMyGameState>(GetWorld()->GetGameState());
    if (IsValid(CastedGameState)) CastedGameState->DestroySubactor(this);
}

```

That is, it calls the DestroySubactor function from the game state on itself.

The first time an instance of SubActorBP calls DestroySelf, then the game freezes anywhere from 5 to 30 seconds, and then the function successfully executes and the game continues as normal. Then any subsequent calls of DestroySelf from _any_ instance of SubActorBP executes smoothly without freezing.

Why does this happen? And how do I prevent the initial freezing? Preferably a method that still calls the c++ function from Gamestate, because that function does other necessary stuff besides destroying the actor.
