Null is undefined

I have some troubles with the FPS tutorial.
Everything worked well until I reached the 4th part and I’ve added the MoveForward and MoveRight functions.
Now, I have 103 NULL is undefined errors and many errors like IntelliSense: cannot open source file “windows.h”, “string.h” and many other headers.

The problem comes from the line:
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxes(EAxis::X);
and in particular from GetScaledAxes() function.

If I don’t call it also the NULL I use in the if checks is recognized.

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#include "FPSProject.h"
#include "FPSCharacter.h"

AFPSCharacter::AFPSCharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

}


void AFPSCharacter::BeginPlay()
{
	Super::BeginPlay();

	if (GEngine)
    {
        GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("We are using FPSCharacter!"));
    }
}

void AFPSCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	// An InputComponent is a component that defines how to handle input data and can be attached to an actor that wants to receive input
	
	// set up gameplay key bindings
    BIND_AXIS(InputComponent, "MoveForward", &AFPSCharacter::MoveForward);
    BIND_AXIS(InputComponent, "MoveRight", &AFPSCharacter::MoveRight);
}

void AFPSCharacter::MoveForward(float Value)
{
	if( Controller != NULL && Value != 0.0f )
	{
		// Get the rotation of our controller
		FRotator Rotation = Controller->GetControlRotation();

		// Ignore the pitch
		if( CharacterMovement->IsMovingOnGround() || CharacterMovement->IsFalling() )
		{
			Rotation.Pitch = 0.0f;
		}

		// Move in the direction found
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxes(EAxis::X);
		AddMovementInput(Direction, Value);
	}
}

void AFPSCharacter::MoveRight(float Value)
{
    if ( Controller != NULL && Value != 0.0f )
    {
        // Find out which way is right
        const FRotator Rotation = Controller->GetControlRotation();
        const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);

        // Add movement in that direction
        AddMovementInput(Direction, Value);
    }
}

Is it a problem in the settings of the project or is it an actual coding error I’ve made?

I thought I had posted an answer, maybe something has gone wrong with it.
Anyway, the problem was that I didn’t include “Engine.h” in the AFPSCharacter class!

Engine.h is one of the more important header files :slight_smile:

hee hee!

Rama

I know that the issue at hand has been solved, but I worry that you would have to manually include Engine.h in your code. It is included for you when you include FPSProject.h in your .cpp files.

The only header includes you should need in the general case should be:

.h

#include "FPSCharacter.generated.h"

.cpp

#include "FPSProject.h"
#include "FPSCharacter.h"

If you wanted to follow it up, you could post your includes for the FPSCharacter.h and FPSCharacter.cpp files and the contents of your FPSProject.h file.

I was thinking what Andrew has written here,

so I second his post :slight_smile:

Rama

Add

  • #ifndef NULL

  • #define NULL 0

  • #endif

Add to the top of your Game.h file :wink:

So it would look like this

#Game.h

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "Engine.h"
#ifndef NULL
#define NULL 0
#endif

Now your entire project has a ifndef NULL keyword, that works!

#Post The Error Please

Can you post the entire compile error please?

I am presuming that Robert’s answer did not resolve this for you?

Rama