// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "BaseCharacterData.generated.h"
UCLASS()
class BP_PLAYERTEST_API UBaseCharacterData : public UObject
{
GENERATED_BODY()
public:
UBaseCharacterData();
~UBaseCharacterData();
// get internal count of all Objects (not really needed)
static int32 GetCount();
private:
// internal object count
static int32 iCount;
public:
// last seen Actor (Targets)
UPROPERTY(Transient)
class AActor* LastOverlappedActor;
float Speed;
};
CPP File:
// Fill out your copyright notice in the Description page of Project Settings.
#include "BaseCharacterData.h"
UBaseCharacterData::UBaseCharacterData()
{
UBaseCharacterData::iCount++;
UE_LOG(LogTemp, Display, TEXT("BaseCharacterData created, number: %d"), UBaseCharacterData::iCount);
LastOverlappedActor = nullptr;
// Default-Speed
Speed = 600.f;
}
UBaseCharacterData::~UBaseCharacterData()
{
iCount --;
UE_LOG(LogTemp, Warning, TEXT("UBaseCharacterData destroyed!: %d"), UBaseCharacterData::iCount);
}
int32 UBaseCharacterData::GetCount()
{
return iCount;
}
// init global object count
int32 UBaseCharacterData::iCount = 0;
Example instanzing → in BaseCharacter.h
...
UPROPERTY(Transient)
class UBaseCharacterData* ObjectData;
...
Maybe you could generate new class in the UE4 Editor. It will do the class declaration for you.
For manually declaring a new class inheriting UObject, some additional things are required:
// FPMovement.h
#pragma once
/* "CoreMinimal.h" has the basic functions of UE4. Almostly always needed. */
#include "CoreMinimal.h"
/* "xxx.generated.h" is always needed as the LAST included file. */
#include "FPMovement.generated.h"
UCLASS()
/*
* For a UClass, you need to add "XXX_API" macro between "class" and your class name. XXX is usually your project name.
* If you don't know what the macro is, just generate a class in the UE4 Editor.
* Also, all UClass inherit UObject as the error says, so write like this:
*/
class XXX_API UFPMovement : public UObject {
// UClass always requires a "GENERATED_BODY()".
GENERATED_BODY()
public:
};
Before getting familiar with UClass declaration, it’s recommended to add new C++ classes and structs in the Editor.