Skip to content

Fix inputs repossess #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ void UGBFHeroComponent::HandleChangeInitState( UGameFrameworkComponentManager *
pawn_ext_comp->InitializeAbilitySystem( player_state->GetGBFAbilitySystemComponent(), player_state );
}

if ( const auto * pc = GetController< AGBFPlayerController >() )
if ( auto * pc = GetController< AGBFPlayerController >() )
{
if ( pawn->InputComponent != nullptr )
{
InitializePlayerInput( pawn->InputComponent );
pc->OnPossessedPawnChanged.AddDynamic( this, &ThisClass::OnPossessedPawnChanged );
}

// Hook up the delegate for all pawns, in case we spectate later
Expand Down Expand Up @@ -255,6 +256,25 @@ void UGBFHeroComponent::OnRegister()
}
}

void UGBFHeroComponent::OnUnregister()
{
Super::OnUnregister();

const auto * pawn = GetPawn< APawn >();
if ( pawn == nullptr )
{
return;
}

auto * pc = pawn->GetController< APlayerController >();
if ( pc == nullptr )
{
return;
}

pc->OnPossessedPawnChanged.RemoveDynamic( this, &ThisClass::OnPossessedPawnChanged );
}

void UGBFHeroComponent::BindToRequiredOnActorInitStateChanged()
{
BindOnActorInitStateChanged( UGBFPawnExtensionComponent::NAME_ActorFeatureName, GBFTag_InitState_DataInitialized, false );
Expand Down Expand Up @@ -394,4 +414,31 @@ TSubclassOf< UGBFCameraMode > UGBFHeroComponent::DetermineCameraMode() const
}

return nullptr;
}

void UGBFHeroComponent::OnPossessedPawnChanged( APawn * /*old_pawn*/, APawn * new_pawn )
{
if ( new_pawn == nullptr )
{
BoundActionsByInputConfig.Empty();
bReadyToBindInputs = false;
return;
}

if ( new_pawn->InputComponent == nullptr )
{
return;
}

if ( bReadyToBindInputs )
{
return;
}

if ( !HasReachedInitState( GBFTag_InitState_DataInitialized ) )
{
return;
}

InitializePlayerInput( new_pawn->InputComponent );
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent

protected:
void OnRegister() override;
void OnUnregister() override;
void BindToRequiredOnActorInitStateChanged() override;
void InitializePlayerInput( UInputComponent * player_input_component );
void Input_AbilityInputTagPressed( FGameplayTag input_tag );
Expand All @@ -70,6 +71,9 @@ class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent
TSubclassOf< UGBFCameraMode > DetermineCameraMode() const;

private:
UFUNCTION()
void OnPossessedPawnChanged( APawn * old_pawn, APawn * new_pawn );

FSimpleMulticastDelegate::FDelegate OnPawnReadyToInitializeDelegate;

// True when player input bindings have been applyed, will never be true for non-players
Expand Down