Hello, although I’m not new to C++ I am new to UE4.
I am working on getting up to speed on how everything works.
I have created a custom class that will be used as a datatype in another class.
Here is a basic custom class:
//Header
#pragma once
#include "Object.h"
#include "TestClass.generated.h"
/**
*
*/
UCLASS()
class MYPROJECT_API UTestClass : public UObject
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Testing)
FString testString;
};
//Body
#include "MyProject.h"
#include "TestClass.h"
UTestClass::UTestClass(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
Here is where I am trying to use the class in my character class:
//Header
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "TestClass.h"
#include "GameFramework/Character.h"
#include "MyProjectCharacter.generated.h"
UCLASS(Blueprintable)
class AMyProjectCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
/** Top down camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
TSubobjectPtr<class UCameraComponent> TopDownCameraComponent;
/** Camera boom positioning the camera above the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
TSubobjectPtr<class USpringArmComponent> CameraBoom;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Testing)
TSubobjectPtr<class UTestClass> test;
};
//Body
#include "MyProject.h"
#include "MyProjectCharacter.h"
AMyProjectCharacter::AMyProjectCharacter(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Set size for player capsule
CapsuleComponent->InitCapsuleSize(42.f, 96.0f);
// Don't rotate character to camera direction
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Configure character movement
CharacterMovement->bOrientRotationToMovement = true; // Rotate character to moving direction
CharacterMovement->RotationRate = FRotator(0.f, 640.f, 0.f);
CharacterMovement->bConstrainToPlane = true;
CharacterMovement->bSnapToPlaneAtStart = true;
// Create a camera boom...
CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
CameraBoom->AttachTo(RootComponent);
CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does
CameraBoom->TargetArmLength = 800.f;
CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f);
CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level
// Create a camera...
TopDownCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("TopDownCamera"));
TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
TopDownCameraComponent->bUseControllerViewRotation = false; // Camera does not rotate relative to arm
}
I am getting the following errors:
error C2039: ‘TestString’ : is not a member of ‘UTestClass’
error C2661: ‘UStrProperty::UStrProperty’ : no overloaded function takes 3 arguments
This seems like it should be fairly straight forward (at least using c++).
Can someone explain how to use custom classes as datatypes in UE4?