I make a BeginOverlap function, get the enemy char out of it.
I put this character into a function.
I create a function that is triggered when F is pressed.
This F key function fetches the enemy char and calls a function from that char.
Where is my mistake?
You need to take the character that triggered the overlap and store it in a member variable of AMyCharacter, instead of calling GibtGegner. Then when you call F_Taste later you can retrieve the overlapped character from the member variable and play an anim montage.
You should also do more error checking as well. Make sure the character exists and is valid before playing the anim montage.
This doesn’t make any sense. The function asks for a character, and it returns the same character that you gave it. So it does nothing basically. This is what I’d do. (Also I’m not sure if AMyCharacter is supposed to be the enemy, or the player class.)
// .h
// The latest enemy character from the overlap check.
UPROPERTY() // <-- Use this every time you are storing pointers in headers. Otherwise the garbage collector will delete it from memory.
AMyCharacter* EnemyCharacter;
// Returns the cached enemy character pointer. Can be null!
AMyCharacter* GetEnemyCharacter();
// .cpp
void AMyCharacter::BeginBoxOverlap(...)
{
AMyCharacter* Enemy = Cast<AMyCharacter>(OtherActor);
if (Enemy )
{
// Cache the enemy character.
EnemyCharacter = Enemy;
}
}
AMyCharacter* GetEnemyCharacter()
{
// Return the character that is set in EnemyCharacter var.
// Returns null if the variable is not set.
return EnemyCharacter;
}
Hi, I’m not sure what you’re asking exactly but if it is why your beginoverlap function is not working it’s probably because there is a bug in UE (at least in 4.26) which is that the collision triggers are not hot-reloaded properly.
Try removing the actor from the scene and adding it again. It works for me.