Skip to main content

Put it all together - Play with friends - (Unreal Engine module)

Last updated on October 24, 2024

Connect the UI to invite friend to game session

  1. Open the InviteToGameSessionWidget_Starter CPP file and navigate to InviteToSession function and replace it with the code below.

    void UInviteToGameSessionWidget_Starter::InviteToSession()
    {
    const UFriendData* FriendData = GetFriendDataFromParentWidget();
    if (!FriendData)
    {
    return;
    }

    // disable button for 5 seconds to avoid spamming
    Btn_Invite->SetIsEnabled(false);
    GetGameInstance()->GetTimerManager().SetTimer(
    InviteDelayTimerHandle,
    FTimerDelegate::CreateWeakLambda(this, [this]()
    {
    Btn_Invite->SetIsEnabled(true);
    }),
    5.0f,
    false,
    5.0f);

    Subsystem->SendGameSessionInvite(GetOwningPlayer(), FriendData->UserId);
    }

Resources