Unusual Errors

I’m new to the Unreal 5 engine C++ API.
I’m receiving an unusual syntax error where one minute I was able to compile and the next minute it returns Live Coding errors.
It’s indicating I need to terminate before the pointer. Any insight would be grateful. Thank you.

UPROPERTY(EditAnywhere)
UCameraComponent* Camera;

 Building PawnEditor...
  Using Visual Studio 2019 14.29.30146 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
  [Adaptive Build] Excluded from Pawn unity file: MyPawn.cpp, Pawn.cpp, PawnGameModeBase.cpp
  Determining max actions to execute in parallel (4 physical cores, 8 logical cores)
    Executing up to 4 processes, one per physical core
  Building 2 actions with 2 processes...
  [1/2] Compile MyPawn.gen.cpp
  H:\Unreal Projects\Pawn\Source\Pawn\MyPawn.h(22): error C2143: syntax error: missing ';' before '*'
  H:\Unreal Projects\Pawn\Source\Pawn\MyPawn.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  H:\Unreal Projects\Pawn\Source\Pawn\MyPawn.h(22): error C2238: unexpected token(s) preceding ';'
  H:\Unreal Projects\Pawn\Intermediate\Build\Win64\UnrealEditor\Inc\Pawn\MyPawn.gen.cpp(73): error C2039: 'Camera': is not a member of 'AMyPawn'
  H:\Unreal Projects\Pawn\Source\Pawn\MyPawn.h(10): note: see declaration of 'AMyPawn'
  H:\Unreal Projects\Pawn\Intermediate\Build\Win64\UnrealEditor\Inc\Pawn\MyPawn.gen.cpp(73): error C2618: illegal member designator in offsetof
  H:\Unreal Projects\Pawn\Intermediate\Build\Win64\UnrealEditor\Inc\Pawn\MyPawn.gen.cpp(73): note: offsetof has a builtin meaning; use /Zc:offsetof- to revert to old, non-conforming definition

MyPawn.h

UCLASS()
class PAWN_API AMyPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AMyPawn();

	UPROPERTY(EditAnywhere)
	UStaticMeshComponent* CubeMesh;  

	UPROPERTY(EditAnywhere)
	UCameraComponent* Camera;

Paste in the complete MyPawn.h file.

Thank you for your help!

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"

UCLASS()
class PAWN_API AMyPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AMyPawn();

	UPROPERTY(EditAnywhere)
	UStaticMeshComponent* CubeMesh; 

	UPROPERTY(EditAnywhere)
	UCameraComponent* Camera;

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

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

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

	void MoveFoward(float Value);
	void MoveRight(float Value);

};

Try #include "Camera/CameraComponent.h". If you use Rider you can just Alt-Enter on the UCameraComponent identifier and it will offer to do this for you. It will also show the UCameraComponent identifier in red to let you know there is a problem.

In your header you need to forward declare UStaticMeshComponent and UCameraComponent by addling class before the type. Then in your C++ you need to include their respective header.

UPROPERTY(EditAnywhere)
class UStaticMeshComponent* CubeMesh;  

UPROPERTY(EditAnywhere)
class UCameraComponent* Camera;

in your C++ add

#include "Camera/CameraComponent.h"
#include "Components/StaticMeshComponent.h"
2 Likes

Thank you! That was it!

Regards,

P

1 Like