How do you put a mesh from a pawn file to an actor file

I have a mesh and skeletal mesh for a character pawn and I have an actor file that will act as a third-person camera. I was thinking of getting the character mesh or skeletal mesh from my pawn character and bring it to the actor file and hook up the character mesh to the springarm.

something like this?
CamArm->SetupAttachment(PawnMesh); //PawnMesh is the mesh form the pawn file

if anyone can awnser I will be eternally gratefull

Hi there, hope you’re doing well :slight_smile:
If I get it right, you can do it by creating an reference to the pawn in your camera class and then get the mesh component and attach to it.
will be something like this:
MyCamera.h

UPROPERTY(EditAnywhere)
AMyPawn* MyPawn;

USkeletaleMeshComponent* MyMesh;

MyCamera.cpp

// Remember to select MyPawn blueprint on MyCamera Blueprint
MyMesh = MyPawn->FindComponentByClass<USkeletalMeshComponent>();

if(MyMesh)
{
    CamArm->SetupAttachment(MyMesh);
}

Build and then open the MyCamera blueprint class and you can select the MyPawn class and then this should work.
If you have any questions, please let me know

Thank you! I’m in class right now but when I home I’ll try it out.

1 Like

No problem, have a nice day in your class. If you face some problem, please let me know

so I gave your code a try, but I got an expeaction thrown error syaing that My pawn(the pawn that I named) is a null pointer. So I tried to connect the camera actor to my pawn class and not it says that the camera actor is now null. AplayerCamera* camera = Cast(GetOwner()); although I did it a little differenetly I keep getting th same error every time I try to make an instance or call the classess. do you know why that is?

oh, sorry about this, I will make some deep tests here and then I can tell you the right way to do this! Can you paste a sample of your code that tries to attach to the pawn please?

I did something a little different after I ran into the error

//this is the playerCam. cpp begin play function

Super::BeginPlay();
character = Cast<APrototypeCharacter>(GetOwner());
PCamArm->SetupAttachment(character->CMesh); 
PCam->SetupAttachment(PCamArm, USpringArmComponent::SocketName);

I was trying this method in my characterPawn class and I saw that it connected somewhat in the data blueprints but it wasn’t visible in the blueprint viewport

Oh, I’m kind of busy right now and I can’t test it pretty well, but i think it was my fault in the declaration of the pawn class in MyCamera.h. To make the Character BP appear on the camera BP, it has to be a TSubclassOf. So in your camera.h, should be something like this:

UPROPERTY(EditAnywhere, Category="Character")
TSubclassOf<AMyPawn> MyPawn;

where the AMyPawn is the pawn class.
So then in your camera BP, in class defaults, should appear a MyPawn variable on the Character category, so you just have to select your pawn BP there and then should stop crashing.
Sorry about my mistake

1 Like

I just woke up from a nap. thank you Ill try it right now

1 Like