#Network Identity children

14 messages · Page 1 of 1 (latest)

formal bobcat
#

I have a player object, inside that player object is the players backpack, when the player dissconnects or dies i want to seperate the backpack from the player, in doing so the backpack needs a network identity, but starting with a network identity on the backpack gives errors since its a child, how can i mitigate this? is it safe to just ignore? and i dont want to spawn the backpack seperatly since its a high CCU game and if its not a child i would have to make clients use extra processing power to align all backpacks and its just not worth it

steep spire
#

Hey,
If you dont need exactly that backpack. You can prepare a backpack prefab that includes a NetworkIdentity. When the player dies or disconnects, you can spawn a new backpack from a drop point using NetworkServer.Spawn(), then transfer the player’s items into this new backpack instance.

This avoids issues with nested NetworkIdentity errors and keeps the system clean and performant.

[Server]
void DropBackpack(Vector3 dropPosition, List<Item> items)
{
GameObject droppedBackpack = Instantiate(backpackPrefab, dropPosition, Quaternion.identity);
NetworkServer.Spawn(droppedBackpack);

// Initialize inventory
droppedBackpack.GetComponent<Backpack>().SetItems(items);

}

like this.

formal bobcat
# steep spire Hey, If you dont need exactly that backpack. You can prepare a backpack prefab t...

alright, i could. another thing is storing items? i have it setup currently so when you store an item it stores as a child of whichever slot you put it in, and puts your item into a SyncList, then other clients when items are added/removed from that list copy it, and having stored items align with the slots every frame wouldnt be viable;

18 slots/items * 200 CCU = 3600 (ontop of having to loop through ALL items which would add a bit more)

spare holly
formal bobcat
#

they need to stay physical items

#

and spawning and despawning items would be a absolute mess with how many players, items and since its something you access often

#

i also dont understand why mirror cant handle childed network identitys, seams like the one thing that wouldnt get in the way

formal bobcat
#

here is currently how my inventory works (even with the errors), if there is a better way to sync the data i am very open to ideas but i dont want to change any functionality

#

i can provide the code for it if needed

spare holly
#

tagging @old roost to help with VR grabbing

old roost
#

@formal bobcat Can new players join after the games started?
Or once its started, no one else joins, might be a quik solution if so.

formal bobcat