Download

char woth skeletal mesh not visible after spawn

Hi, i am using following code to spawn a custom char class containing skeletal mesh … but after spawn it is not showing up in the game … how ever debug message says class not null…

char.h

UCLASS()
class TREBUCKET_1_API Atb_enemyCharacter : public ACharacter
{
GENERATED_BODY()

public:
// Sets default values for this character’s properties
Atb_enemyCharacter();

UAnimSequence* IdleAnim;

UCapsuleComponent* capsule1;
USkeletalMeshComponent* skMesh;
UMaterialInterface* mansQmat;

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

};

char.cpp
Atb_enemyCharacter::Atb_enemyCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

capsule1 = CreateDefaultSubobject<UCapsuleComponent>(TEXT("capsule_1"));
RootComponent = capsule1;
capsule1->SetCapsuleHalfHeight(96.f);
capsule1->SetCapsuleRadius(42.f);

skMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("SK_MESH1"));
skMesh->AttachToComponent(capsule1, FAttachmentTransformRules::KeepRelativeTransform);
skMesh->bHiddenInGame = false;

static ConstructorHelpers::FObjectFinder<USkeletalMesh> skMeshAsset(TEXT("/Game/TB_1/Mannequin/Character/Mesh/SK_Mannequin.SK_Mannequin"));

if (skMeshAsset.Succeeded())
{
    skMesh->SetSkeletalMesh(skMeshAsset.Object);
    skMesh->SetRelativeLocation(FVector(0.f, 0.f, -97.f));
    skMesh->SetRelativeRotation(FRotator(0.f,0.f,270.f));
    skMesh->SetVisibility(true, true);
    //skMesh->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::AlwaysTickPoseAndRefreshBones; //deprecated
    skMesh->VisibilityBasedAnimTickOption = EVisibilityBasedAnimTickOption::AlwaysTickPoseAndRefreshBones;

}


static ConstructorHelpers::FObjectFinder<UAnimSequence> animObj(TEXT("/Game/TB_1/Mannequin/Animations/ThirdPersonIdle.ThirdPersonIdle"));
IdleAnim = animObj.Object;

mansQmat = CreateDefaultSubobject<UMaterial>(TEXT("manQmat_1"));

static ConstructorHelpers::FObjectFinder<UMaterial> skMatAsset(TEXT("/Game/TB_1/Mannequin/Character/Materials/M_UE4Man_Body.M_UE4Man_Body"));

if (skMatAsset.Succeeded())
{
    skMesh->SetMaterial(0, mansQmat);
}

}

// Called every frame
void Atb_enemyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

skMesh->PlayAnimation(IdleAnim, true);

}

game play mgr class.h

UPROPERTY()
    Atb_enemyCharacter* randomEnemy;

game play mgr class.cpp

at begin play()

FVector randomEnemyLoc(0.f, 0.f, 0.f);
FRotator randomEnemyRot(0.f, 0.f, 0.f);
FActorSpawnParameters randomEnemySpawnInfo;
randomEnemySpawnInfo.Owner = this;
randomEnemySpawnInfo.bNoFail = true;
randomEnemySpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
randomEnemy = GetWorld()->SpawnActor<Atb_enemyCharacter>(randomEnemyLoc, randomEnemyRot, randomEnemySpawnInfo);
randomEnemy->SetActorLocation(FVector(0.f, 0.f, 100.f));
randomEnemy->SetActorScale3D(FVector(4.f));
randomEnemy->SetActorHiddenInGame(false);
if (randomEnemy)
{
    FVector loc = randomEnemy->GetActorLocation();
    GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SPAWN SKMESH RANDOM ENEMY"));
    GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, FString::Printf(TEXT("RANDOM %f %f %f"), loc.X, loc.Y, loc.Z));
}