Make sure you have included the .h file for your ABaseCharacter class in the .cpp file of your ABaseWeapon class. The compiler needs to know that you’re assigning a pointer of a type that converts to APawn/AActor.
Sure, if each of the headers has classes containing members of each other, then that is impossible. And unless you have forward declarations then things can still break. In general having forward declarations in headers instead of includes is best practice (where possible).
Your setup should be something like this, Redemp:
BaseCharacter.h:
#pragma once
#include "GameFramework/Character.h"
class ABaseWeapon;
UCLASS()
class ABaseCharacter : public ACharacter
{
GENERATED_BODY()
public:
UPROPERTY()
ABaseWeapon* MyWeapon;
};
BaseWeapon.h:
#pragma once
#include "GameFramework/Actor.h"
class ABaseCharacter;
UCLASS()
class ABaseWeapon : public AActor
{
GENERATED_BODY()
public:
void SetOwningPawn(ABaseCharacter* NewOwner);
ABaseCharacter* MyPawn = nullptr;
};
BaseWeapon.cpp:
#include "BaseWeapon.h"
#include "BaseCharacter.h"
void ABaseWeapon::SetOwningPawn(ABaseCharacter* NewOwner)
{
if (MyPawn != NewOwner)
{
Instigator = NewOwner;
MyPawn = NewOwner;
// net owner for RPC calls
SetOwner(NewOwner);
}
}
It is possible to have circular dependencies even if use #pragma once.
I have seen that once before, which was introduced by 4 classes (Character-MethodPicker-Method-Object) when attempting using Strategy Pattern. I solved in converting all unnecessary include in headers files to only forward-declare on the global scope and added all needed in .cpp files.
If that possible to provide the source of your project to pinpoint where the includes go crazy?