Download

Abstract UCLASS has unclear error

I’m trying to create a class deriving from ACharacter that acts as an abstract base class for player characters and NPCs, holding common data such as name, hair color, etc. However, UBT seems to whine about this and it’s an “unknown” error (error code 5). I really hope there’s a way to get some useful info out of what it’s not liking instead of “oh, it’s a misc. error, good luck finding out what you did wrong”

Here are the source files. I’m posting it as a whole because I put a UENUM in it. I’m not sure if UE4 C++ acts like Java in the sense that I can have only one structure per source file or not, but MSVC underlines in red the UCLASS macro usage, the “private:” section, and the ending curly brace of the class.


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

#pragma once

#include "GameFramework/Character.h"
#include "EntityBase.generated.h"

UENUM(blueprinttype)
enum class ERace: uint8
{
	Human, Elf, Gnome, Dwarf
};

UCLASS(abstract) // error
class FANTASYGAME_API AEntityBase: public ACharacter
{
	GENERATED_BODY()
public:
	AEntityBase();

	UFUNCTION(blueprintcallable)
	float GetHeight() const;

	UFUNCTION(blueprintcallable)
	void SetHeight(float);

	UPROPERTY()
	FLinearColor HairColor;

	UPROPERTY()
	FLinearColor EyeColor;

	UPROPERTY()
	FString Name;

	UPROPERTY()
	int16 HairPreset;

	UPROPERTY()
	int16 FacePreset;

	UPROPERTY()
	ERace Race;

	UPROPERTY()
	bool bFemale;

private: // error
	float Height;
}; // error

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

#include "FantasyGame.h"
#include "EntityBase.h"

AEntityBase::AEntityBase() // AEntityBase isn't recognised
{
	PrimaryActorTick.bCanEverTick = true; // PrimaryActorTick is undefined it says
}

inline float AEntityBase::GetHeight() const
{
	return Height; // says it's not declared
}

inline void AEntityBase::SetHeight(float Value)
{
	Height = Min(Max(Value, .5f), 2f); // Min/Max aren't either
}

Error 5 happens because the UBT finds an error in your markup, like the UPROPERTY macros, and doesn’t report that error back to VS. I elaborated in this post: Unspecific/Unhelpful build errors? - C++ Gameplay Programming - Unreal Engine Forums Check that for more details on how to see the actual error.

int16 cannot be used as a UPROPERTY, that may be the cause. You can use only uint8 or int32.