From f31f0437e9169e1cf6804c89a6f9ae3bfef067f2 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sat, 10 Jun 2023 19:23:21 -0400 Subject: [PATCH] Setup input mapping in player controller --- .../Input/FFPlayerController.cpp | 16 ++++++++++++++++ .../Input/FFPlayerController.h | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp index 69327b3..a1a75e7 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp @@ -5,16 +5,32 @@ // FF includes #include "FFInputBufferComponent.h" +// UE includes +#include "EnhancedInputSubsystems.h" + AFFPlayerController::AFFPlayerController() { InputBuffer = CreateDefaultSubobject(TEXT("InputBuffer")); } + void AFFPlayerController::SendInputsToRemote() const { } + void AFFPlayerController::SetupInputComponent() { Super::SetupInputComponent(); + + if (ULocalPlayer* LocalPlayer = Cast(Player)) + { + if (UEnhancedInputLocalPlayerSubsystem* InputSystem = LocalPlayer->GetSubsystem()) + { + if (!DefaultInputMapping.IsNull()) + { + InputSystem->AddMappingContext(DefaultInputMapping.LoadSynchronous(), 0); + } + } + } } diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.h b/Source/UnrealFightingFramework/Input/FFPlayerController.h index 8420133..0c4bba3 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.h +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.h @@ -2,9 +2,13 @@ #pragma once +// FF includes +#include "FFInputBufferComponent.h" + // UE includes #include "CoreMinimal.h" #include "GameFramework/PlayerController.h" +#include "InputMappingContext.h" #include "FFPlayerController.generated.h" @@ -23,7 +27,7 @@ public: /** * Sends all unacknowledged inputs to the remote */ - void SendInputsToRemote() const; + virtual void SendInputsToRemote() const; // APlayerController interface virtual void SetupInputComponent() override; @@ -32,7 +36,7 @@ public: protected: /** MappingContext */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true")) - class UInputMappingContext* DefaultMappingContext; + TSoftObjectPtr DefaultInputMapping; /** Input Buffer component */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true"))