How can I define a variable in this kind

I want to write a function can pick a mesh from game with a gun,but which kind of variable should I use?I doun’t know the target is USkeletalMesh or a UStaticMesh.I must define a variable to save the target, and the variable can save both USkeletalMesh and UStaticMesh.

This ultimately relies on the model you are importing. A rigged model will be a skeletal mesh, whilst an unrigged model is always going to be static mesh. Skeletal meshes have moving parts, but static meshes do not (Hence the static).

A gun(? Your question isn’t too clear) is usually animated, so I would assume that you will be wanting to use a skeletal mesh.

sorry for my describe,I want to know is there a kind of variable can also save USkeletalMesh and UStaticMesh.Or how can I know a aactor is AStaticMeshActor or ASkeletalMeshActor.

Ok.

To determine what type of mesh you want, the simplest way is to just determine if there will be an animation (A ‘UAnimationAsset’). If your model does not change at all, just use a static mesh.

If you wan’t to use both, just keep a pointer to both a static and skeletal mesh component, and toggle the visibility.

TLDR:
If it moves without physics use a Skeletal Mesh, anything else is a Static Mesh

I means determine the it with code,I search the fourm and find out the way,the function ->IsA(AStaticMeshActor::StaticClass()) can help me.

In your actors header, add

USkeletalMeshComponent* SkeletalMesh;

This is a pointer to the component that you are going to add to your actor.

Now in the CPP file, add this to your constructor

    // Collect then set the skeletal mesh
    static ConstructorHelpers::FObjectFinder<USkeletalMesh> MeshObj(TEXT("PATH_HERE")); // Replace PATH_HERE with the path to the asset, eg. /Game/GunMesh
   SkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh")); // Create a new component
    SkeletalMesh->SetSkeletalMesh(MeshObj.Object); // Set to the mesh we just got

This is some code from my project. Snoop around if you are still having trouble: Header Definition