I want to use state pattern in multiplayer environment.
Lets say I have:
UCLASS()
class UBaseState : public UObject
{
GENERATED_BODY()
public:
};
UCLASS()
class UOpenState : public BaseState
{
GENERATED_BODY()
public:
// some logic
};
UCLASS()
class UClosedState : public BaseState
{
GENERATED_BODY()
public:
// some logic
};
I want to create state on a server.
And then I wan’t to store pointer in some actor and replicate it, so client will avare about current state.
UCLASS()
class AMyActor : AActor
{
GENERATED_BODY()
public:
UPROPERTY(Replicated);
BaseState * CurrentState;
};
How to I delete previous state and creates the new one? Is this gonna work?
void AMyActor::ChangeState()
{
if(CurrentState->IsValid())
{
// How do I delete current state?
{
CurrentState = NewObject<UClosedState>();
}
void AMyActor::SomeMethodOnAClient()
{
if(Cast<UStateClosed>(CurrentState))
{
// is this gonna work?
}
}