I am not sure if this is the right way to achieve the aim, which is, invoking the OnFire method defined in ACharacter from a UBrainComponent instance. So in ACharacter class I define SetupPlayerInput method as
void AShooterAIDummy::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
// set up gameplay key bindings
check(PlayerInputComponent);
// Bind fire event
FireAction = &PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &AShooterAIDummy::OnFire);
// Bind other stuff
}
Then I copy the pointer to some AInfo (named MAIGameState) class (again through the ACharacter method)
void AShooterAIDummy::BeginPlay()
{
Super::BeginPlay();
// Method to talk to gamemode. Store self referance in Gamemode and let MAI posses itself
GameMode = GetWorld()->GetAuthGameMode<AShooterAIGameMode>();
if(GameMode)
{
GameMode->GetMAIGameState()->SetFireBindDelegate(FireAction);
}
}
Finally in the UBrainComponent, I invoke the OnFire method by
GetGameState()->GetFireBindDelegate()->ActionDelegate.Execute("");
It works for some time in the beginning of the game (120 seconds or so), then the delegate unbinds. I think it is the garbage collection and may I need to add AddToRoot() somewhere but I am not sure.
I think it is relevant to InputBindings on UObjects issue with delegates - C++ Gameplay Programming - Unreal Engine Forums