Hello,
In our multiplayer game, each player always has two characters spawned, and they can switch control between them at any time. We are using GAS for their abilities and it’s working fine.
What we want to achieve now is something like the following:
Player is controlling character A and starts pushing a button. This causes the camera (and posession) to change to character B, allowing the player to aim. When the button is released, character B shoots a projectile and camera and posession goes back to character A.
What I’ve tried so far is having 2 different abilities. Ability A handles possessing character B and making it activate Ability B, waiting for it to end. Ability B handles the aiming, waiting for the input release and shooting the projectile.
Ability A code looks something like:
void UAbility_A::ActivateAbility(...)
{
// ...
// Possess Character B
if (HasAuthority(&CurrentActivationInfo))
{
AOurGameMode::ChangePossession(Character_A, Character_B);
}
// Activate Ability B in Character B
Character_B->GetAbilitySystemComponent()->TryActivateAbilityByClass(UAbility_B::StaticClass());
// Task that waits for Ability B to end
UAT_WaitAbilityEnd* WaitAbilityEndTask = UAT_WaitAbilityEnd::CreateWaitAbilityEndTask(this, UAbility_B::StaticClass(), Character_B);
WaitAbilityEndTask->OnAbilityEndedDelegate.AddDynamic(this, &ThisClass::OnAbilityBEnded);
WaitAbilityEndTask->ReadyForActivation();
}
void UAbility_A::OnAbilityBEnded(UGameplayAbility* EndedAbility)
{
// ...
// Possess ourselves back
if (HasAuthority(&CurrentActivationInfo))
{
AOurGameMode::ChangePossession(Character_B, Character_A);
}
// End Ability
EndAbility(...);
}
This is working fine when playing as the server, but not on clients though.
Since possession is done in server, when client tries to force Character B to activate Ability B, it fails because Character B is a simulated proxy.
Also, when ability is executed server side, Ability B activation replication to client fails too, since apparently when the client RPC gets to client, Character B is still simulated proxy.
I’ve also tried having a task that makes client wait for the controller replication to Character B after posession, but in that exact moment Character B is still a simulated proxy, and haven’t found a way to be notified when the Role changes.
Is there any way that we could make this work? Is this approach reasonable at all? Or maybe what we want to achieve is better done in a different way. Any hint on this would be very much appreciated.
Thanks a lot for your time.