Download

Basic C++ Tutorial problem with undefined identifiers.

Hi guys,

So this is embarrassing, but I’m having trouble with one of the more basic C++ programming tutorials: Player Input and Pawns.

So following the steps I get to the point where I have to create a variable of type UCameraComponent, only when trying to do so this indentifier is undefined.

I’ve been trying to see if I’ve not included something, or created the class or project wrong, but after some googling and looking through code myself I can’t seem to get anywhere.

Sorry for the basic question, but I’d really appreciate some help, without further talking heres the code:

MyPawn.h



// 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 MYPROJECT_API AMyPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AMyPawn();

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

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

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

	
	UPROPERTY(EditAnywhere)
		USceneComponent* OurVisibleComponent;
};


MyPawn.cpp



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

#include "MyProject.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(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}



the line it’s erroring on:



	UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));


Thanks in advance guys.

Just to add some more info. I’ve tried this on 2 machines now just to see if the install was bad, and it’s the same issue for both. I’m currently abandoning the tutorial to come back to it after I’ve learnt some more in the hope that I’m being stupid and when more used to Unreal I can correct this problem quickly.

Add “#include “Camera/CameraComponent.h”” to your class header that is using the UCameraComponent.



#pragma once

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


4.16 changed the way you need to handle what classes you are using. Engine.h is no longer used as it was, meaning you have to include what you want.

Here is more information on that:

https://docs.unrealengine.com/latest/INT/Programming/UnrealBuildSystem/IWYUReferenceGuide/

You can also simply use the version of the engine that the tutorial was written for, reducing the risk of issues like this.

Thanks Kyle!

I’ll have a read up on this, by any chance to do you know what version they were written for? I may just try and keep in mind these changes and be mindful of it going forward.

Thanks very much for your help!

All of the tutorials should have a mention to what engine version used when they were written .
Current_View.png

“You can also simply use the version of the engine that the tutorial was written for, reducing the risk of issues like this.”

That is a shocking answer. Considering that Unreal takes up tens of gigabytes, it is likely new users will have just one version of the engine installed. There is only one version of the tutorials for each subject, so the user has no choice but to use the only available tutorial. It is completely insane to have an expectation that a new user will only run the tutorials (or even realise this could be an issue) that match their engine version.

Are you actually saying that, as I’m using 4.21.1, all the programming tutorials are now junk? They don’t compile, so I suppose you’re on to something. How will I learn to implement C++ using Unreal? Guesswork?

Here is what your answer should say “God, that’s embarrassing - the tutorials don’t even compile anymore? We will get that sorted as a matter of urgency, because that’s the new user’s route into deciding to use Unreal, Unity or some other competitor product. Can’t believe we let this slip through the net. In the meantime, here are the changes you will need in order to make the first and most basic C++ tutorial actually compile using the latest versions of VS and Unreal Engine.”

/\ Except since Fortnite started making billions, supporting or teaching new comers is far from being a priority…

All demo projects are still updated tho; if you can’t learn by studying those demos you’re bound to have a very hard time learning to use this engine.
Tutorials and videos will always become outdated, this engine will never stop to change.

If this is that shocking to you, you have not been a developer long. If you have been a developer, then stop your trolling.

Developers know that developing is the main priority. Yes, given a perfect world with perfectly available resources the documentation and subsequent hand holding would ensue. Be alas, all you have is the complete source code listing between each version.