Replicating objects?

So it would seem that I can’t replicate uobjects, only items derived from the actor class.

But I don’t want these objects to actually spawn in game (you can’t "create an actor class using CreateObject, you need to spawnactor which needs an in game location).

Whats a neat solution to this conundrum ?

You are correct in seeing that UObjects can’t be replicated. Only Actors and ActorComponents (components) can be replicated. You can replicate Structs through Actors and components, using them as little data containers.

Actors don’t actually need an in-game location-- there is such a thing as Actors with no components at all (such as the GameMode). So don’t think of an Actor as something that must have a transform or must be visible.

As a summary: You’ll need to use Actors and components to do replication, but you can use Structs in them to group some data together.

Hope this helps!


I suspected as much, I just wanted to be sure before I ripped apart my inventory system !

I’ll have a go and report back.

However now I am reading that the inventory should really be all client side with only the interface that’s updated (via rep notify). Would that also work if I kept my inventory using uobjects ?

I’m not completely sure, but I think you’ll still need to switch away from using plain UObjects.
I think using Structs would be best for an inventory.

Depends on whether your doing multiplayer or single player. For multiplayer you want the server to manage and control inventory.

Player adds item: player requests to add, server validates and adds it, replicates the addition back to player.

This prevents cheating.

Inventory client side ? what do you mean the HUD part ? OFC it is client side
The DATA part, the information of your inventory should be Server side… In my opinion you are free to do it however you want.

Remember the server is like the god manipulating and the clients just mortals : P Stupid example I know but hey it works.

Once the mortal dies, the server should know what items the client has to show the items on floor to the other mortals Clients…

If only mortal knows and can manipulate em then he can cheat easily… well I am no hacker but come on it is way easier to manipulate your computer than 1000 KM away computer. AKA server

If you have technichal questions I can answer them to…

OK so currently a players inventory is held in a component of the player character. So is that held on the players PC (client, or the server), or can I choose (by specifying which code runs where) ?

Gotta admit I might be a bit hazy on some of this stuff.

Well a simple authority check should be enough? If has authority means is server if not, means is client. That way you choose. In most cases has authority works fine to run the code from server or client.

I don’t fully understand the philosophy of authority but I can asure that in most cases when has authority means is server.

There’s also “Is Server” and “Is Dedicated Server” bool you can run on a branch.

You can also to check if is server, controller is PlayerController Index 0 ?

’ I don’t want to work this explanation a lot since it is confusing '.

The inventory is a component of FirstPersonBlueprint.

The game doesn’t use a dedicated server, so the “server” is also running the game. i.e. it has is running the game client code too, with an instance of the FirstPersonBlue Print and an inventory component.

So just did a little test - where by the a routine would list inventory items and would run only on the server.

This routine ONLY lists whatever inventory the player character on the server owns.

This proves there isn’t a copy of everyone’s inventory on the server, only the players inventory that happens to be running on the server.

SO if I want everone’s inventory to be on the server - I’ll have to put inventory in game state ? and add an inventory component when a player joins ?

Mine is stored in the player controller… AC_Inventory.

Hmm poking about the internet - player state feels like the best place for the inv to go.

But to some extent the blueprint which contains the Inv component is irrelevant. The updates need to be done server side. SO… how do you get your GUI to pull from the server side component ?

Or do you mean, updates occur on the server only, but the data object is replicated - so the client receives a copy of that data via replication ? If so… this is where I came in. My inventory is an array of uObjects and uObjects DON’T replicate.

Could I implement server side functions to return the information to the GUI, and bind the GUI’s text boxes to those ?

“Actors don’t actually need an in-game location-- there is such a thing as Actors with no components at all (such as the GameMode). So don’t think of an Actor as something that must have a transform or must be visible.”

BUT SpawnActor REQUIRES a Spawn Transform node. Meaning it will appear in the game level. So how do I construct a object of type Actor that doesn’t appear in the game level ?

Did you find a solution to this? i’m kind of running on a similar problem.

I changed my inventory to actors - these spawn at 0,0,0 but I don’t assign a skeletal mesh so you can’t see or interact with them.

If you drop an object - then I give it a mesh :slight_smile:

Does that help ?