Problem with SpawnActor On Server

Hello!

So I’m working on a Multiplayer Project and when I’m dragging out the item form the inventory, the game should spawn an the item actor. The spawn item function is in the GameStateBase and It is called from a Widget Blueprint. In the widget blueprint I can’t use Switch has Authority, so I have to do the things in the GameStateBase.
Now it works like I drop an item from Client1, he can see and pick it up correctly again, but Client2 can’t see it and pick up correctly, if Client2 tries to pick it up it gets delete to Client1 too, which is understandable.
I tried a lot of things to make it work, but it still doesn’t work correctly. Anyone can help me out a bit? ':smiley:

You should be using the gamestate to talk to something like gamemode to communicate to the server for this kind of replication from a client player so you can accurately keep track of the item. You want to run the spawn actor of class on the server or host. The component of that actor should be replicated too if you want others to see it and be able to pick up that item. iirc that’s gonna be a ‘run on server’ and because the actor is set as replicated, you don’t need a second custom event to be ran as a multi-cast from the run on server to spawn it on all players’ screens.

For things like actor transform of dropping player, you want to make sure that you have a variable being carried directly from one event to next to ensure that variable is retained when called on the server. If you had a customevent run on server for example and them put get player location, it’s going to get the server player’s location.

Hmm… I’m not quite understand. So I have to use the gamestate to talk to the gamemode to communicate to the server. How can I do this and where should I put the run on server event?

For now I know that GameState is a server owned actor, I can’t use things like i used. So I have to use it in a client owned class. I did it in the PlayerController and now it gets executed, but the SpawnItem function has a UObject input, which contains the information about the item. Now this gets invalid in the RunOnServer Event. I think I checked everything, anyone has any idea for that?
Thanks!

First things first. You need to ensure that the item being dropped is set to be replicated and replicate movement. Once you ensure that, when you call the action to drop the item which I would assume you’re actually spawning at the owner’s transform, you need to ensure that from the moment you are calling the action, the transform is designated as an input/output to each one of the steps it takes through other blueprints until it is finally called in GameStateBase.

So if you’re starting in player controller to drop an item, you would get the controlled pawn’s transform, create a run on server custom event w/ an input of that transform, if you’re going to call get GameState and cast to GameStateBase, you’ll need to set the next event or function to have an input of transform type and then tie that into the actual item drop sequence.

I figured it out with structs, cause UObject doesn’t replicate by default so I can’t put object on the server, because it gets invalid.