Tutorial code not working?

I was trying to do the First Person Shooter tutorial and a couple other tutorials within it such as Player input and Pawns but when I put in the code myself or copy it exactly as it shows in the tutorial I just get a list of errors when I build or compile. If the coding is wrong it’s not much of a tutorial but i’m not sure if it might be an issue on my end or not. I was able to do the Programming quick start fine.

you need to provide some information for us to work with. show us the code and the errors. also you never really asked a question

Code as stated by the tutorial (https://docs.unrealengine.com/en-US/Programming/Tutorials/PlayerInput/1) to be put in then compiled but comes up with a bunch of errors so I can’t continue.
// Fill out your copyright notice in the Description page of Project Settings.

#include "HowTo_PlayerInput.h"
#include "MyPawn.h"

// Sets default values
AMyPawn::AMyPawn()
{
	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	// Set this pawn to be controlled by the lowest-numbered player
	AutoPossessPlayer = EAutoReceiveInput::Player0;

	// Create a dummy root component we can attach things to.
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	// Create a camera and a visible object
	UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
	OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));
	// Attach our camera and visible object to our root component. Offset and rotate the camera.
	OurCamera->SetupAttachment(RootComponent);
	OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));
	OurCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
	OurVisibleComponent->SetupAttachment(RootComponent);
}

// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
	Super::BeginPlay();

}

// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);

}

In your MyPawn.cpp change your includes to look like this:

#include "MyPawn.h"
#include "HowTo_PlayerInput.h"
#include "Camera/CameraComponent.h"

In your MyPawn.h change:

USceneComponent* OurVisibleComponent;

to:

UStaticMeshComponent* OurVisibleComponent;

It will now compile.

About your .cpp:

  1. Make sure the primary header for the *.cpp is always first in your includes. In this case #include “MyPawn.h” would need to be the first include always.

  2. Sometimes for other classes you will need to add a header for it. I often have to include headers for components. I showed you the include for the camera. Tip: most other includes will be in #include “Runtime/Engine/Classes/…” incase you are ever looking for something.

About your .h:

  1. Obviously this tutorial is out of date and furthermore the tutorial is plain wrong. Sorry you had to go through this. They put the wrong class in their .h. Obviously you create a UStaticMeshComponent and add it to a UStaticMeshComponent variable. I’m not sure why they said USceneComponent. . .

  2. Tip: Just incase it’s also good to know for your .h that your .generated.h will always need to be the last include. Which is #include “MyPawn.generated.h” in this case. Which it is and it’s fine. Just mentioning this fact just incase for future reference.

1 Like

First of all somethings might be missing.and most of ur things are undefined. so did u even used the .h file?
please put the whole .cpp and .h file so we can help.
and do wht koala said

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"

UCLASS()
class HOWTO_PLAYERINPUT_API AMyPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values
	AMyPawn();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:
	// Called every frame
	virtual void Tick(float DeltaSeconds) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

	UPROPERTY(EditAnywhere)
		USceneComponent* OurVisibleComponent;
};

I updated my answer down below. You can now compile your code and I left some detailed explaination. I know it sucks to learn all this. I hope you keep going!

Thanks for the help, not gonna bother continuing with their tutorials if they don’t work.