Hey Guys,
I have Usable interface with UFUNCTION(reliable, server, WithValidation) ServerOnUse() and Pickup class (child of Usable and Actor) and Weapon_Pickup class (child of Pickup). When i call the ServerOnUse in editor, it crashes with an error to use Execute_ServerOnUse. Sadly, when i do that it doesn’t use my overriden _Implementation and _Validation functions in Weapon_Pickup, so it ends up doing nothing. Any ideas how to work around this?
Usable.h
#pragma once
#include "MyCharacter.h"
#include "Usable.generated.h"
/** Class needed to support InterfaceCast(Object) */
UINTERFACE(MinimalAPI)
class UUsable : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class IUsable
{
GENERATED_IINTERFACE_BODY()
virtual void OnUse(AMyCharacter* Who) PURE_VIRTUAL(IUsable::OnUse, );
UFUNCTION(reliable, server, WithValidation)
virtual void ServerOnUse(AMyCharacter* Who);
};
Usable.cpp
#include "Shooter.h"
#include "Usable.h"
//////////////////////////////////////////////////////////////////////////
// Usable Interface
UUsable::UUsable(const class FObjectInitializer& OI)
: Super(OI)
{
}
bool IUsable::ServerOnUse_Validate(AMyCharacter* Who){
return true;
}
Pickup.h
UCLASS(Abstract)
class SHOOTER_API APickup : public AActor, public IUsable
{
GENERATED_UCLASS_BODY()
void ServerOnUse_Implementation (AMyCharacter* ToWho) PURE_VIRTUAL(APickup::ServerPickUp_Implementation, );
};
Pickup_Weapon.h
UCLASS()
class SHOOTER_API APickup_Weapon : public APickup
{
GENERATED_UCLASS_BODY();
void ServerOnUse_Implementation(AMyCharacter* Who) override;
bool ServerOnUse_Validate (AMyCharacter* Who) override;
void OnUse(AMyCharacter* Who) override;
};
Pickup_Weapon.cpp
void APickup_Weapon::ServerOnUse_Implementation(AMyCharacter* Who){
GEngine->AddOnScreenDebugMessage(-1, 2.0, FColor::Blue, TEXT("server on use"));
OnUse(Who);
}
bool APickup_Weapon::ServerOnUse_Validate(AMyCharacter* Who){
return true;
}
void APickup_Weapon::OnUse(AMyCharacter* Who){
if (Role == ROLE_Authority){
Destroy(true);
}
else{
Execute_ServerOnUse(this, Who); // Using ServerOnUse(this) crashes
}
}