Creating an AActor in c++ and Setting the Mesh In Blueprint Properties and spawning in c++

what you do is right. except on the spawnActor you must not spawn from the static class you must get the respected blueprint and get the generated class from there the code must be something like this ::

AWeapon_Scar* weapon = Cast(World->SpawnActor([yourblueprintreference]->GeneratedClass)));

I have created an AActor class via c++, with a static mesh component. I then set the mesh via the blueprint property editor. If I spawn one of these AActors via c++ it does not have the properties I set in the blueprint. Is there a way to do this?

AWeapon_Scar.h

UPROPERTY(VisibleAnywhere, Category = "Weapon", meta = (AllowPrivateAccess = "true"))
	class UStaticMeshComponent* StaticMeshComponent;

AWeapon_Scar.cpp

AWeapon_Scar::AWeapon_Scar()
{
    StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
    RootComponent = StaticMeshComponent;
}

I Create a blueprint from this base class, set the mesh via the class defaults window, then save and compile.
If I drag the blueprint on to my level everything works fine.

If I try to spawn a new one via c++ it has none of the properties I set in the blueprint.

AWeapon_Scar* weapon = (AWeapon_Scar*)World->SpawnActor(AWeapon_Scar::StaticClass());

Is it possible to do what I’m trying to do? I really don’t want to hard code my resource variables.