TSubClassOf is NULL

I tried to follow the Shooter example’s bullet spawning method.
I create a c++ class for the weapon.
The header contains the TSubClassof fot the spawn event
public:

	UPROPERTY(EditDefaultsOnly, Category = Projectile)
	TSubclassOf<class AW01Projectile> ProjectileClass;

The blueprint ProjectileClass is setted to BP_AW01Projectile.
When I use ProjectileClass it says the class is NULL

Any solution?

You sure you setting ProjectileClass in right object? Where do you call it?

I call it from the weapon class W01Weapon.cpp

You’ll need to show how you are calling it. I am thinking that is where the mistake is.

It doesn’t mind how I call… I add a function to check the state of the projectile class and it return false while GameplayStatics::BeginSpawningActorFromClassgive me warning log saying the class is NULL

bool FPSCharacter::GetProjectile()
{
       if (ProjectileClass)
       {
           return true;
        }
       else
       {
           return false;
       }
}

Ok then where you set it?

BP_W01Weapon, ProjectileClass box

posting your code would be nice

W01Weapon.h

#pragma once

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

UCLASS()
class W01_API AW01Weapon : public AActor
{
	GENERATED_UCLASS_BODY()
	
	virtual void PostInitializeComponents() override;
    
public:
	UPROPERTY(EditDefaultsOnly, Category = Projectile)
	TSubclassOf<class AJanoProjectile> ProjectileClass;

void SetOwningPawn(AW01Character* AW01Character);

private:
	UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
	USkeletalMeshComponent* Mesh1P;

protected:

UPROPERTY(Transient, ReplicatedUsing = OnRep_MyPawn)
class AW01Character* MyPawn;

	UPROPERTY(Transient, Replicated)
	int32 CurrentAmmo;

	UPROPERTY(Transient)
	int32 MaxAmmo;

UFUNCTION()
void OnRep_MyPawn();

    bool GetProjectile();

public:
	AW01Weapon();
}

W01Weapon.cpp

#include "W01.h"
#include "W01Weapon.h"
#include "UnrealNetwork.h"
#include "W01Character.h"
#include "Engine.h"
#include "W01Projectile.h"

AW01Weapon::AW01Weapon(const FObjectInitializer& ObjectInitializer)
{
	Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh1P"));
	Mesh1P->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::OnlyTickPoseWhenRendered;
	Mesh1P->bChartDistanceFactor = false;
	Mesh1P->bReceivesDecals = false;
	Mesh1P->CastShadow = false;
	Mesh1P->SetCollisionObjectType(ECC_WorldDynamic);
	Mesh1P->SetCollisionEnabled(ECollisionEnabled::NoCollision);
	Mesh1P->SetCollisionResponseToAllChannels(ECR_Ignore);
	RootComponent = Mesh1P;
   
	CurrentAmmo = 0;

	PrimaryActorTick.bCanEverTick = true;
	PrimaryActorTick.TickGroup = TG_PrePhysics;
	SetRemoteRoleForBackwardsCompat(ROLE_SimulatedProxy);
	bReplicates = true;
	bNetUseOwnerRelevancy = true;

}

void AW01Weapon::PostInitializeComponents()
{
	Super::PostInitializeComponents();

	MaxAmmo = 100;
	CurrentAmmo = 40;

}

void AW01Weapon::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(AW01Weapon, MyPawn);

	DOREPLIFETIME_CONDITION(AW01Weapon, CurrentAmmo, COND_OwnerOnly);

}

void AW01Weapon::OnRep_MyPawn()
{
	if (MyPawn)
	{
		OnEnterInventory(MyPawn);
	}
}

    void AW01Weapon::OnEnterInventory(AW01Character* NewOwner)
{
	SetOwningPawn(NewOwner);
}

void AW01Weapon::SetOwningPawn(AW01Character* NewOwner)
{

	if (MyPawn != NewOwner)
	{
		Instigator = NewOwner;
		MyPawn = NewOwner;
		SetOwner(NewOwner);
	}
}

bool AW01Weapon::GetProjectile()
        if (ProjectileClass)
        {
            return true;
         }
        else
        {
            return false;
        }
 }

Eveything seems ok to me if you set class in defaults, so only possible things is you refrenceing to UClass in wrong place, so where do you call GetProjectile()?

try using normal pointer instead of TSubClassOf ans see if it works. My guess would be type error

also, in your weapon class you inherited from AActor, so try changing GENERATED_UCLASS_BODY() to GENERATED_BODY()

I still using GENERATED_UCLASS_BODY() and didn’t have issue UClass’es

In the Character.cpp I use

void AW01Character::SpawnDefaultWeapon()
{
	if (Role < ROLE_Authority)
	{
		return;
	}
	FActorSpawnParameters SpawnInfo;
	SpawnInfo.bNoCollisionFail = true;
	AW01Weapon* NewWeapon = ()->SpawnActor<AW01Weapon>(SpawnInfo);
	NewWeapon->GetProjectile();
}