Error setting Static mesh from child class

Hi everyone,

I am quite new to c++ coding and coding in ue4.
I am trying to make an Interaction system with item pickups in C++ using the following tutorial series:…5ySJrFOqFgqzy-

I made a c++ class called Interactable and i made a child c++ class from that called Pickup.

when trying to set the static mesh in Pickup.cpp it gives me the following error:

1> Private\Pickup.cpp(10): error C2440: '=': cannot convert from 'TReturnType *' to 'USkeletalMeshComponent *'
1>          with
1>              TReturnType=UStaticMeshComponent
1>          ]
1> Private\Pickup.cpp(10): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I make the Static mesh property in Interactable.h:

    void Interact();
    virtual void Interact_Implementation();

    UPROPERTY(EditAnywhere, Category = "Interactable Properties")
    class USkeletalMeshComponent* InteractableMesh;

Then in Pickup.cpp i am trying to make it into an CreateDefaultSubobject but here it gives me the error.


APickup::APickup() {

    InteractableMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));

How can i fix this problem?

Thanks in advance!

It says, it can not convert from your **UStaticMeshComponent **to USkeletalMeshComponent which is set in your HEADER file
you have created it as

  UPROPERTY(EditAnywhere, Category = "Interactable Properties")     class USkeletalMeshComponent* InteractableMesh; 

So you need to create it as USkeletalMeshComponent, but not like UStaticMeshComponent. Please try this out!

or if you do not need it as a USkeletalMeshComponent you can change it to UStaticMeshComponent and then create it as a UStaticMeshComponent w/o issues

Thanks for the help!
Such a beginner mistake but i think everyone has them! :wink:

Yeah, I think everyone does this seldom.
It is always good to check output log, and sometimes it can be due to lack of some mudules projectName.Build.cs file or because you do not include something or forget to specify the class before the className

Good luck, and do not hesitate to ask others!