Hi,
I’m trying to do this (see screenshot ) in c++
I want to attach AStaticMeshActor (NightwishStaff) to a socket.
I wrote a blueprint callable function which looks like this:
void AManaJourneyCharacter::equipItem(AActor* actorToEquip, FName SocketName)
{
// set default properties or the equipment in Editor
actorToEquip->SetActorEnableCollision(false);
actorToEquip->AttachRootComponentTo(this->GetMesh(), SocketName, EAttachLocation::SnapToTargetIncludingScale, false);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("EQUIPT %s"), *actorToEquip->GetName()));
// remove any custom depth for equipped items
TArray<UStaticMeshComponent*> StaticMeshesList;
actorToEquip->GetComponents<UStaticMeshComponent>(StaticMeshesList);
for (int32 i = 0; i < StaticMeshesList.Num(); i++)
{
UStaticMeshComponent* StaticMeshComponent = StaticMeshesList[i];
StaticMeshComponent->SetRenderCustomDepth(false);
}
}
When I’m creating a reference in the blueprint to the Actor I like to equip, everything works fine.
But I plan to do this in pure c++ so I did this to get the NightStaff item from c++.
bool equiped = false;
for (TObjectIterator<AStaticMeshActor> act; act; ++act)
{
FString actorName = act->GetName();
if (actorName.Contains("NightwingStaff") && !equiped)
{
equipItem(*act, "Staff");
equiped = true;
}
}
EquipItem has no error but it is not working and I cannot figure it out in the debugger…