So i came up with neat little system where i do 2 things
- Create a Usable interface with methods:
void Interact(AActor* UsingActor)
void SetStatus(AActor* UsingActor, bool Usable) //For telling an actor that its usable or not to blink or something
So that i can add it to all the actors in the level to make them instantly usable by the another thing - InteractionComponent that inherits from sphere component that will work with actors with Usable interface by Setting their statuses and raycasting.
in .cpp i have
void UInteractionComponent::OnPotentialUsableCollisionEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
IIUsable* PotentialUsable = Cast<IIUsable>(OtherActor);
if (PotentialUsable)
{
PotentialUsable->SetStatus(GetOwner(), true);
UsablesInRange.Add(PotentialUsable);
}
}
void UInteractionComponent::OnPotentialUsableCollisionEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
IIUsable* PotentialUsable = Cast<IIUsable>(OtherActor);
if (PotentialUsable)
{
PotentialUsable->SetStatus(GetOwner(), true);
UsablesInRange.RemoveSingle(PotentialUsable);
}
}
void UInteractionComponent::InitializeComponent()
{
OnComponentBeginOverlap.AddDynamic(this, &UInteractionComponent::OnPotentialUsableCollisionEnter);
OnComponentEndOverlap.AddDynamic(this, &UInteractionComponent::OnPotentialUsableCollisionEnd);
}
in .h i have
GENERATED_BODY()
void OnPotentialUsableCollisionEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
void OnPotentialUsableCollisionEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
virtual void InitializeComponent() override;
public:
UPROPERTY(BlueprintReadWrite, Category = "Interaction Component")
TArray<TScriptInterface<IIUsable>> UsablesInRange;
And im completly baffled by this error message
error C2664: ‘void FScriptInterface::SetObject(UObject *)’ : cannot convert argument 1 from ‘IIUsable *’ to ‘UObject *’
Can anyone shed some light on this?