SpawnActor failed because no class was specified

I have created a class called ABlock::

I have created another class called AGrid::

inside AGrid I want to spawn ABlock::

Grid.h

// The type that the input should try to be cast to
	UPROPERTY()
	TSubclassOf<class ABlock> BlockClass;

Gridd.cpp

ABlock *NewBlock = GetWorld()->SpawnActor<ABlock>(BlockClass, TheLoc, TheRot, SpawnInfo);

Result:

LogSpawn:Warning: SpawnActor failed because no class was specified

what did I do wrong?

Can anyone help?

Thanks. You should have written it as a new comment because I can’t accept it as the answer otherwise :slight_smile:

1 Like

I don’t get how come in the FPS tutorial they do

/** Projectile class to spawn */
    UPROPERTY(EditDefaultsOnly, Category=Projectile)
    TSubclassOf<class AFPSProjectile> ProjectileClass;

   AFPSProjectile* const Projectile = World->SpawnActor<AFPSProjectile>(ProjectileClass, MuzzleLocation, MuzzleRotation, SpawnParams);

Can you use ABlock::StaticClass() instead of BlockClass to successfully spawn a new ABlock?

I think in the FPS tutorial they expose a property so you can set it to any type of projectile you want. The problem with your implementation is that you never actually fill the BlockClass property with a value (ie. a type of class derived from ABlock).

If you’re always going to spawn ABlocks you can stick with ABlock::StaticClass(), but you can use the FPS example to make it dynamic.