在线编译器 C

#pragma once #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "InputActionValue.h" #include "AMyPlayer.generated.h" UCLASS() class MYPROJECT_API AMyPlayer : public ACharacter { GENERATED_BODY() public: AMyPlayer(); /** Input Actions */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputMappingContext* DefaultMappingContext; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* MoveAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* LookAction; protected: virtual void BeginPlay() override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; /** Input Handlers */ void Move(const FInputActionValue& Value); void Look(const FInputActionValue& Value); };
This header declares a custom ACharacter subclass with three input-related UPROPERTY pointers and two input handler functions.

- The forward declarations use the class keyword inside the UPROPERTY lines, which is fine, but make sure the corresponding .cpp includes the headers for UInputMappingContext and UInputAction, otherwise the pointers stay incomplete types.
- In SetupPlayerInputComponent you will need to bind MoveAction and LookAction to the Move and Look functions; check that the binding uses the correct trigger event (for example ETriggerEvent::Triggered) and that DefaultMappingContext is added to the local player subsystem in BeginPlay.