Something About Inventory's Items in Multiplayer.

Hello Everyone,

I want to make an Inventory system for my MMORPG game, so my design was to create an inventory as a dynamic buffer of Entities (Items) in the Server assembly side. I have many different types of items, so each item type is based on a unique collection of components.

My question is I want to create the item entity as normal in server side (without Ghost Component), but maybe the Netcode prevent it and the created Entity seems disposed after creation and don’t need the item to be replicated to all client and I will sync the item stats throw RPCs to the owner client specially item stats do not change frequently it’s only change when do some crafting on it.

Is there any way to do that or even make it a ghost item but only replicate to its owner client?

public struct Inventory : IBufferElementData
{
    public Entity Item;
}

public struct ItemStats : IComponentData
{
    public int Id;
    public FixedString64Bytes Name;
    public ItemType Type;
    public FixedString64Bytes Sort;

public enum ItemType
{
    PhyWeapon,
    MagWeapon,
    Shield,
    .....
}
}

That is what happen when add a normal entity into buffer:

internal BufferLookup<Inventory> inventory;
var item = ECB.CreateEntity();
ECB.AddComponent<ItemStats>(item);

inventory[playerEntity].Add(new Inventory { Item = item });

It gives me Invalid entity inside the buffer.


“Player’s Inventory Component”


“The Item Entity in Entities Hierarchy”

Is my design wrong with ECS? Need to hear from you.

Thanks in advance.

Hey OrientedPain, a similar question was posted a while ago, you may find it useful: About Ghost spawning and components synchronization

Thank you for your response, the post you mentioned is very useful.

I have solved the issue; I was trying to access the new entity in the same frame. The issue I’m experiencing is related to the order of execution of systems and the EntityCommandBuffer. When I use an ECB to create an entity and add components, the changes are not applied immediately. Instead, they are applied after the system that created the ECB finishes its update and the ECB is played back.

I do not know how I forgot something like that. :):slight_smile: