I have a Pawn object in C++ which had earlier a static mesh as root component.
I used ReceiveActorOnClicked for getting clicks which worked perfectly.
Meanwhile I added animation and changed static mesh to skeletal mesh.
Strangely, ReceiveActorOnClicked doesnt work anymore (neither ReceiveActorBeginCursorOver etc).
Also tried add dynamic event:
OnClicked.AddDynamic(this, &AWorldUnit::UnitClicked);
but same, method not hit…
please let share with me, if you have any idea…
hm seems it hits but on very small piece of mesh the click noticed… I made a clickfest on it…
what can be the cause?
OK, it is confirmed:
ReceiveActorOnClicked and other events are active UNTIL skeletal mesh not animated.
when animation is ON, events ceased to hit.
anyways, it seems not related to animation but skeletal meshes and their physical assets.
actually click through ReceiveActorOnClicked only received if I click to STATIC mesh parts (like weapon) of my pawn.
https://answers.unrealengine.com/questions/104739/bug-with-trace-and-onclick-events.html
this post from the above link seems like it is still an ongoing problem? though the post is from 2014…
so in summary what I did and where I stopped:
- I have a pawn with C++ code which assembles a Pawn with skeletal mesh, static mesh and animation components
- C++ method ReceiveActorOnClicked not triggered on skeletal mesh
- the skeletal mesh has a Physics Asset, tried with box, sphere collision objects attached to bones (Add Box, Add Sphere, … in Physic Asset editor)
- tried several collosion modes (Box, Sphere) but neither works…
someone seems solved this with creating a static mesh surrounding skeletal mesh and set it hidden for game, then click works again.
maybe anyone has a better idea or solution?
maybe it is related only to C++ solution and I missed sth when created the pawn in the code?
(skeletal mesh had valid pointer for physical asset, but I tried set it manually with SetPhysicsAsset, with the same no result)
AWorldUnit::AWorldUnit(const class FObjectInitializer& PCIP)
: Super(PCIP)
{
static ConstructorHelpers::FObjectFinder<USkeletalMesh> UnitMesh(TEXT("SkeletalMesh'/Game/Units/soldier_animated.soldier_animated'"));
static ConstructorHelpers::FObjectFinder<UMaterial> UnitMaterial(TEXT("Material'/Game/Materials/Unit_Clothing_Mat.Unit_Clothing_Mat'"));
static ConstructorHelpers::FObjectFinder<UMaterial> RifleMaterial(TEXT("Material'/Game/Units/Rifle_material.Rifle_material'"));
static ConstructorHelpers::FObjectFinder<UMaterial> FlagMaterial(TEXT("Material'/Game/Units/Unit_flag_material.Unit_flag_material'"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> RifleMesh(TEXT("SkeletalMesh'/Game/Units/rifle_noanim.rifle_noanim'"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> FlagMesh(TEXT("SkeletalMesh'/Game/Units/flag_noanim.flag_noanim'"));
static ConstructorHelpers::FObjectFinder<UAnimBlueprint> AnimBP(TEXT("AnimBlueprint'/Game/Units/UnitAnimatorBP.UnitAnimatorBP'"));
static ConstructorHelpers::FObjectFinder<UPhysicsAsset> Physics(TEXT("PhysicsAsset'/Game/Units/soldier_animated_Physics.soldier_animated_Physics'"));
_pUnitMesh = PCIP.CreateDefaultSubobject < USkeletalMeshComponent >(this, TEXT("Unit"));
_pUnitMesh->SetSkeletalMesh(UnitMesh.Object);
_pUnitMesh->SetPhysicsAsset(Physics.Object);
_pFlagMesh = PCIP.CreateDefaultSubobject < UStaticMeshComponent >(this, TEXT("Flag"));
_pFlagMesh->SetStaticMesh(FlagMesh.Object);
_pRifleMesh = PCIP.CreateDefaultSubobject < UStaticMeshComponent >(this, TEXT("Rifle"));
_pRifleMesh->SetStaticMesh(RifleMesh.Object);
_pUnitMesh->SetAnimInstanceClass(AnimBP.Object->GeneratedClass);
_pAnimBP = PCIP.CreateDefaultSubobject < UAnimBlueprint >(this, TEXT("Animation"));
FVector new_scale = FVector(0.2f, 0.2f, 0.2f);
_pUnitMesh->SetRelativeScale3D(new_scale);
_Instance1 = _pUnitMesh->CreateAndSetMaterialInstanceDynamicFromMaterial(0, UnitMaterial.Object);
_MaterialFlag = _pFlagMesh->CreateAndSetMaterialInstanceDynamicFromMaterial(0, FlagMaterial.Object);
_Instance3 = _pRifleMesh->CreateAndSetMaterialInstanceDynamicFromMaterial(0, RifleMaterial.Object);
SetRootComponent(_pUnitMesh);
AddInstanceComponent(_pRifleMesh);
AddInstanceComponent(_pFlagMesh);
// values copied from editor, setting component positions
_pFlagMesh->SetRelativeLocationAndRotation(FVector(-2.301296, 3.824689, -7.207497), FRotator(5.680313, -125.867767, 11.492057));
_pRifleMesh->SetRelativeLocationAndRotation(FVector(-0.000019, 2.80532, -10.705698), FRotator(14.399689, 0, 0));
_pFlagMesh->AttachParent = _pUnitMesh;
_pFlagMesh->AttachSocketName = FName(TEXT("LeftHandSocket"));
_pRifleMesh->AttachParent = _pUnitMesh;
_pRifleMesh->AttachSocketName = FName(TEXT("PelvisSocket"));
_pUnitMesh->SetRelativeLocationAndRotation(FVector(0, 0, 0), FRotator(0, 0, 0));
PrimaryActorTick.bCanEverTick = true;
}
// toggles animation of clicked pawn
// it receives only if static mesh under mouse, doesnt work on skeletal even it has physical asset
void AWorldUnit::ReceiveActorOnClicked()
{
Super::ReceiveActorOnClicked();
if (_pUnitMesh->GlobalAnimRateScale == 0)
_pUnitMesh->GlobalAnimRateScale = 1;
else
_pUnitMesh->GlobalAnimRateScale = 0;
..
}
so Im not sure it is 100% related to C++ and I just need to set sth in editor for physics asset or skeletal mesh.
well, I forced to pick a solution recommends using a hidden, covering static mesh on skeletal mesh getting the clicks.
it works, thought not the most elegant solution, Im still curious why my physical assets linked to skeletal didnt work.