When i create a c++ project, code doesnt work at all

I have created a c++ project, i want to make a First Person Shooter, so i have already created the XTypeCharacter.h and cpp, and a blueprint from that, but no matter what i type of code, changes are not visible in the editor, i have compiled the project, fixed some errors, but now that they are no errors the code doesnt seems to work or do anything at all. Here it is my character class.-

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


#include "XTypeCharacter.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"


// Sets default values
AXTypeCharacter::AXTypeCharacter()
{
 	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
    
    CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
    CameraBoom->SetupAttachment(RootComponent);
    CameraBoom->TargetArmLength = 300.f;
    CameraBoom->bUsePawnControlRotation = true;
    
    FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
    FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
    FollowCamera->bUsePawnControlRotation = false;
    

}

// Called when the game starts or when spawned
void AXTypeCharacter::BeginPlay()
{
	Super::BeginPlay();
	
}


void AXTypeCharacter::MoveForward(float Value)
{
    if((Controller != nullptr) && (Value != 0.0f))
    {
        const FRotator Rotation{ Controller->GetControlRotation() };
        const FRotator YawRotation{ 0, Rotation.Yaw, 0 };
        
        const FVector Direction{ FRotationMatrix{YawRotation}.GetUnitAxis(EAxis::X) };
        AddMovementInput(Direction, Value);
    }
}

void AXTypeCharacter::MoveRight(float Value)
{
    if((Controller != nullptr) && (Value != 0.0f))
    {
        const FRotator Rotation{ Controller->GetControlRotation() };
        const FRotator YawRotation{ 0, Rotation.Yaw, 0 };
        
        const FVector Direction{ FRotationMatrix{YawRotation}.GetUnitAxis(EAxis::Y) };
        AddMovementInput(Direction, Value);
    }
}

// Called every frame
void AXTypeCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AXTypeCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
    
    check(PlayerInputComponent);
    
    PlayerInputComponent->BindAxis("MoveForward", this, &AXTypeCharacter::MoveForward);
    PlayerInputComponent->BindAxis("MoveRight", this, &AXTypeCharacter::MoveRight);
}

Here it is the header


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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "XTypeCharacter.generated.h"

UCLASS()
class XTYPE_API AXTypeCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	AXTypeCharacter();

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

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

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

private:
    
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class USpringArmComponent* CameraBoom;
    
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class UCameraComponent* FollowCamera;
    
public:

    
    FORCEINLINE USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
    
    FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; }
	
};

When i open the Blueprint theres no spring arm, neither a camera following the Character
1 Like

A Suggestion: use Forward Declaration.
//in .h remove the below include
include “GameFramework/SpringArmComponent.h”
//and use this instead
class USpringArmComponent;

UCLASS()
class XTYPE_API AXTypeCharacter : public ACharacter

{
GENERATED_BODY()

private:

///Also if you are using UE5 you should use TObjectPtr<className>
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = “true”))
TObjectPtr<USpringArmComponent> CameraBoom;

I have tried to compile with the Editor and with the IDE, the result its the same, I use CodeLite IDE becouse QTCreator doesnt open when i double click a code file. I honestly dont know if CodeLite IDE its well configured, i have begun using the IDE very soon. Heres a image when i compile.


If i Add TObjectPtr the compiler throws me 15 errors. UPDATE.- i have added a * and now it works no errors from the compiler
TObjectPtr* CameraBoom;

I have also created the logic for moving with the wsad keys, but when i press play it doesnt move. I am not an expert but CodeLite seems to work ok, and if so, why does the code do not perform any action?

I have not used codelite, but I can guide to configure QTCreator.

If using QT-Creator then set editor preference > code editor > null source code access

  1. Could you rename the Unreal Projects folder to UnrealProjects as it might cause problem in the future (Not an issue here, but can cause potential issue when zipping project and running some other stuff)
  2. Then generate the project again by right clicking and selecting “Generate Project Files”
  3. make some edit on the source files to so that it re-compiles!
  4. open a console and try to compile the project with code in 5. (just for testing)
  5. /home/jorgecg/UnrealEngine5/UnrealEngine-ue5-early-access/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool Linux Development -TargetType=Editor -Progress -Project=“/home/jorgecg/Documentos/UnrealProjects/Xtype/XType.uproject” -j$(nproc)
  6. If it compiles then set the same configuration in the QTCreator projects>Build. Override/bin with UBT location ( /home/jorgecg/UnrealEngine5/UnrealEngine-ue5-early-access/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool), and for make arguments give the rest ( Linux Development -TargetType=Editor -Progress -Project=“/home/jorgecg/Documentos/UnrealProjects/Xtype/XType.uproject” -j$(nproc) ).

PS: steps 5-6 are hacks for a bug in UE5-EarlyAcess and UE5-main which was reported by NachoMonkey2 (fix).
In future ignore 4-5-6. and instead use $make project from console or from QT creator click build (using qmake).

I have renamed the folder, no spaces, but now CodeLite cant display the files

This image shows IDEs i can use in Unreal, some dont even open, and i dont like Visual Studio Code because it cant compile, not an expert but never liked it

Unreal and CodeLite cant open now my project, i will try to compile with terminal… Compiling from the terminal has found this error…

its working from console and you have an error in .h . when using TObjectPtr should not have * on variable. only class name!

I cant open the project in CodeLite, I think that it has been enought for me for today, i will continue tommorow morning, thank you for helping me, i have this problem since the morning. Thank you sam

Now when i compile, QTCreator throws errors in UCameraComponent instances it says “Undeclared identifier” UPDATE.- I have just included the header, now everything works, i can see the spring arm and the follow camera Thank you for everything

1 Like