Moving a UStaticMeshComponent with code

Hello, for the past few days I am struggling with this coding problem.

I have an actor class named Item from which I made a blueprint. The blueprint consists of a USphereComponent which is the RootComponent and a UStaticMeshComponent which is parented to the USphereComponent.

I store these items in a TArray to prototype an inventory idea. If I move my cursor over the item, it saves a reference to the item in my inventory TArray. Now what I am trying to do is when pressing a key, the first item in that TArray appears where my mouse cursor is.

It does move the RootComponent, but the UStaticMeshComponent does not want to move. The following image shows the 2 marked lines where I am trying to move the actor in code. The first one works which moves the RootComponent. The second won’t work.

I hope that someone would know why the mesh won’t move.

Much thanks,

MrB

#Set Mobility Movable

you have to specifically tell Static Mesh Components that they can move!

This is set to static by default for lighting optimization reasons

//Mobility
StaticMeshComponent->SetMobility(EComponentMobility::Movable);

your case

//Mobility
ItemMesh->SetMobility(EComponentMobility::Movable);

#:heart:

Rama

Thanks for the anwser Rama.