How to fix a Syntax Error on variable declaration of custom class?

While it may seem like you DMHeaderList.h has the right ordering, the error seems to be that at the time Spell.h is compiled it doesn’t understand what ADMagicCharacter is.

It is probably because of the circular dependency in your headers. DMHeaderList.h includes Spell.h which includes DMHeaderList.h.

In this case you can forward declare your used of the ADMagicCharacter. Simple add the word “class” in front of your member variable, or better yet put “class ADMagicCharacter” right below your include files and above the class declaration.

Additionally, something to remember, is ALWAYS use UPROPERTY above UObject member variables or you will have garbage collection issues. Your Caster variable will be set to null on the first opportunity to garbage collect and you’ll crash if you access it. Or at least you will get bad behavior.

Spell.h

#pragma once

#include "GameFramework/Actor.h"
#include "Spell.generated.h"


...
// Forward declarations here (as long as its pointer type or const& and you don't need the internal details this will be fine)
// any time you use the implementation of the class, put it in the cpp and include DMagicCharacter.h there 
class ADMagicCharacter;
class AProjectile;

UCLASS()
class DMAGIC_API ASpell : public AActor
{
	GENERATED_BODY()
	
public:	
	
	// Sets default values for this actor's properties
	ASpell(const FObjectInitializer& ObjectInitializer);

...
	UPROPERTY()
    ADMagicCharacter* Caster;

...
	UPROPERTY(VisibleAnywhere, Category=Spells)
AProjectile* SpellProjectile;

...

};

DMagicCharacter.h

#pragma once

#include "GameFramework/Character.h"
#include "DMagicCharacter.generated.h"
//try to only include what you use  
//DMHeaderList.h is going to get too big and cause you future headache

...

UCLASS(config=Game)
class ADMagicCharacter : public ACharacter
{
	GENERATED_BODY()

...

public:
	ADMagicCharacter(const FObjectInitializer& ObjectInitializer);

...

};

DMHeaderList.h

#pragma once
#include "Engine.h"
#include "DMagicGameMode.h"
#include "DMagicCharacter.h"
#include "Spell.h"
#include "Projectile.h"