Hello,
I have my own interaction component that belongs to the default player. Whenever I click on certain objects, I want some action to happen depending on the clicked object.
As of now I’m using what I’m sure is a really dirty strategy: for each actor I want to interact with, I’m creating a component to perform a specific action, and after getting the result from LineTraceSingleByObjectType I differentiate basing on the actor name. For example:
if (ActorName.Equals("SM_Lever_24"))
{
ActorHit->FindComponentByClass<ULeverPullComponent>()->ActivateLeverPull();
}
else if (ActorName.Equals("SM_Lock_Key_38"))
{
//...
}
else if (...)
Of course, this has to change.
Another solution that I found about is creating custom classes inheriting from AActor for each actor I want to interact with, write the logic directly in there (thus no component) and then differentiate by casting. For example:
AMyLeverClass* LeverActor= Cast<AMyLeverClass>(ActorHit);
if (LeverActor)
{
LeverActor->PullLever();
return;
}
AMyKeyClass* KeyActor= Cast<AMyKeyClass>(ActorHit);
if (KeyActor)
{
KeyActor->Pick()
}
...
This solution is a bit more general but still kinda ugly…
Last solution I thought about is using LineTraceSingleByChannel / LineTraceSingleByObject (still have to study them so I don’t quite get the difference). creating a custom channel that I will assign to each of the actors I want to interact with, but more importantly I will create a custom base class which will have some kind of function “ProcessInteraction()” and all the actors I want to interact with will inherit from this, implementing their own version of ProcessInteraction.
I’d like to have opinions from people more skilled than me, on if my last solution is good, or if there are any other more standard/stable/efficient solutions. Thanks in advance.