How to get a clicked object

Hi,

I’m creating an item/inventory system. At this point I got items spawned in the world, but now I want to click on the object/mesh of the item to pick the item up and put it in the inventory. I’m stuck at how to detect which object/BaseItem is being clicked.

I tried the following code in the constructor of my BaseItem class:


//Create the static mesh component
ItemMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ItemMesh"));
RootComponent = ItemMesh;
ItemMesh->SetSimulatePhysics(true);
ItemMesh->OnClicked.AddDynamic(this, &ABaseItem::OnClicked);

The Onclicked.AddDynamic gives me an error:
Error (active) no instance of function template “FComponentOnClickedSignature::__Internal_AddDynamic” matches the argument list

Help please!

I want to store the clicked BaseItem in a variable so I can add it to the Inventory array

Thanks in advance!

your on clicked function should look like this

void OnClicked(UPrimitiveComponent* pComponent)

originally copied from OnClicked Parameters - Programming & Scripting - Unreal Engine Forums

Thanks! That got rid of the error. Now I need to get the onclicked function to actually do something, so far no success. But I will get back here with question should I not find a solution.