Hello, I have code that for a custom button in C++ with two methods:
CPP_Button
UFUNCTION()
Client_OnClick()
UFUNCTION(Server, Reliable)
Server_OnClick_Implementation()
The logic that Server_OnClick_Implementation depends on is in a separate class called the Spawner, which has a TQueue of Actors in a line within the world. When the button is clicked, I call the Server OnClick and it is supposed to pop the next actor from the queue (for me to work with) and return it (as well as create another actor, add it to the queue, and have it line up at the end).
CPP_Spawner
int ActorQueueSize;
TQueue<AActor*> ActorQueue;
void GetNext()
I tried to have the Spawner both replicated and not-replicated but so far have not had luck making it work like it is in my head. I prefer not-replicated because I feel this really should exist only on the server and the actors are the only part that need to be replicated to the client. TQueue cannot be a replicated property, so instead, I have a single Actor variable that I set to the “next” actor whenever I call GetNext().
Right now, it works perfectly for just the server. If I press the button on the client, it tells me that there are no actors in the queue and the NextGuest pointer is nullptr (possibly because it’s looking at the client’s version of the Spawner and queue)?
How I want this to work:
- User presses button in the widget, Client_OnClick() is called
- Client_OnClick() calls Server_OnClick()
- Server_OnClick_Implementation gets called on server
- STAYING ON THE SERVER: GetNext() is called from a pointer to the Spawner in Server_OnClick_Implementation.
- Server Spawner examines own TQueue and does a Dequeue, storing the popped actor to NextActor
- STILL ON SERVER: NextActor is received in Server_OnClick_Implementation.
- NextActor is already replicated to the client (from creation) and any movement and state is also replicated to it.
Is there a way to accomplish this?