Spawning Item On Server To Clients

Hey everyone Im trying to set up an inventory system that when I drop an Item from my inventory it spawns in the world for all the players. If i spawn the item on the players side it spawns fine but when i try and pass it back to the Server and then multicast to everyone else it fails and i get the error saying none trying to spawn Actor from class.

You cannot easily replicate objects via RPC parameters like you are trying to do with ItemObject. It sends a reference over the network, but on the other side that reference most likely doesn’t resolve to anything and becomes None. You should change the parameter of both RPCs to be the ItemClass directly, instead of ItemObject.

1 Like

So I need to pass in a Item Object Reference into the spawned item. However if i pass through the Item class directly it spawns but i can’t add its information in

So this way spawns the item fine for everyone however I can’t get the Item Object Input as seen on the spawn actor in the other image.

You should make a struct to contain that data rather than an object.
Structs will transfer fine as RPC parameters.

1 Like

Will that show up on the spawn actor input though? As if it doesnt show for the struct either i’m still in the same situation haha

Yes you can use a struct variable with “expose on spawn” just the same.

1 Like

So adding a Structure to the Item And Exposing it on spawn didnt make it appear on the spawn Actor Node

Hmm none of the exposed variables appear on the Spawn node ?
Your Class parameter might not be specialized enough. Make sure it is the exact same Class type as what you are getting in the result of “Get Item Class”.

1 Like

[quote=“Chatouille, post:9, topic:1599006, username:Chatouille”]
our Class parameter might not be specialized enough. Make sure it is the exact same Class type as what you are getting in the result of “Get Item Class”.
[/

So I rand a print string on both the client and the server and they both come back with the correct Item to spawn. I wonder if its due to passing the Item class through a custom event that it doesnt recongise the Class in the spawn actor until it actually runs the code

It’s not about the value but more so about its type. The SpawnActor node will create dependent pins according to the type that is fed to the input pin. If you connect a generic “Actor Class” it won’t generate any additional pins because Actor doesn’t have any “expose on spawn” properties. You need a pin of type “Item Class” or whatever that class is where you added expose on spawn properties.

1 Like

You got it! That was indeed the issue. I have the Custom Events Class to just plain old actor instead of Master Item Class. You a legend thank you :smiley:

The server should be managing inventory. Meaning clients do not “literally” pick up, add, or drop items.

Clients should interact locally as far as a trace and any needed animation. Then call the server to do a trace/interact. If it’s successful there, the item is picked up and added.

Part of the pick up process on the server is to destroy its instance. Said instance should be a replicated actor. By destroying on the server it will be destroyed on all clients.

Dropping goes through the same process. Client wants to drop, RPC’s server to do it. Server validates, then removes item from inventory, and spawns a replicated actor.

Clients “Request” an action. Server determines if its a valid request and if so executes the action.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.