Class member and TArray are given an error as unidentified UCLASS USTRUCT or ENUM. UE4.26

Hello

I’m guessing you’re not including the “ABaseClassWeapon.h” on your C++ class header, and then the compiler is not recognizing the TArray type! There are two things, in my opinion, you can do here:

  1. Include “BaseClassWeapon.h” on the class header file
  2. Declare the TArray as "TArray< class ABaseClassWeapon* > WeaponArray;

When you use “class” you’re writing a “forward declaration” of the variable type. This is useful so you don’t have to include the other class itself on your .h file (saving unreal from copying and pasting the whole ABaseClassWeapon.h to this .h file).

However, if you need to access a method or member variable from ABaseClassWeapon on the .cpp file of this class, then you have to include “ABaseClassWeapon.h” on your .cpp. Moreover, if you ever need a struct, enum, etc… from ABaseClassWeapon.h to be visible on this .h file, than you have to include it here, and not on the .cpp

Hope I as clear enough! Cheers.

1 Like

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Weapon”)
class ABaseClassWeapon* Weapon;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeaponArray")
   TArray<ABaseClassWeapon*> WeaponsArray;