Ok, so i think i found the problem.
This was the entire function:
void AKeyPickUp::PickKeyUp()
{
if (canPickUpKey)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, TEXT("Called PickKeyUp() function"));
HasKey = true;
this->Destroy();
}
}
I only get this error when i use any variable from the KeyPickUp class. Otherwise, when i only call ‘GEngine->AddOnScreenDebugMessage’, it works perfect.
For explanation: the bool ‘canPickUpKey’ is true, when the player overlaps with the sphere collider of this actor. Only in this sphere, the player can pick up the key. But, as i said, it’s irrelevant which variable i use in this function, i’m always getting “Access violation when writing to position 0x0000000000000330”…