#Random Inventory Repl/Desync

1 messages · Page 1 of 1 (latest)

rigid pecan
#

If groups containing these AI with random inventories are placed on the map -- all clients see the same stuff, including server.

If a group spawns at runtime, server and clients do NOT see the same amount of items

#

Client 1 and 2 for instance will see same counts. Server will see half of whatever they see

undone gyro
#

Try to use TrySpawnPrefab on InventoryStorageManager, instead of spawning yours

#

and Execute this code only on master. Maybe you execute it both on client and server, which generate 6 mags

rigid pecan
#

I’ll try that. It only runs on the authority. Each client has it in their logs that it exits the inventory script.

Since it’s randomized, if clients were to run I would expect to see different items between clients but they’re all the same, minus the discrepancy in counts.

rigid pecan
#

Still duplicates with TrySpawnPrefab

hmmm 🤔

#

(background is authority), front is peer tool

rigid pecan
#

Is there some weirdness of spawning/syncing items?

My logs clearly show the server is the only one spawning items. Clients exit the method because they're not the owner.
In my loops I even print what is getting spawned. Nothing on clients.

It almost feels like whatever syncs the spawn is duplicating. Whatever the server spawns - the clients see double.

rigid pecan
# undone gyro Try to use TrySpawnPrefab on InventoryStorageManager, instead of spawning yours

I think I found a bug, or at least a behavior that isn't making sense. Any time an item is inserted from server into a sub-storage it gets duplicated when players are connected.


So as you've seen I've been trying to add items to AI when they spawn in - help spice things up.

I setup a replication test world where 3 things happen

After 20 seconds (to give peer tool time to load) - the spawn events kick off

  1. Spawn an AI, specifically add and equip backpack. Then insert a magazine
  2. Spawn an AI, do the random stuff
  3. Spawn backpack AND magazine into a box

My findings show anytime an item is inserted within a subitem - it gets duplicated.

For instance, the crate is easier to visualize.
If I don't specify a storage component for the magazine, it gets inserted into the backpack. IF it's in the backpack it gets duplicated!!!!!!!!
If i specify adding the magazine to the crate's storage component it DOES NOT get duplicated

https://github.com/TrainWreckers/Extraction/blob/replication-testing/Scripts/Game/Components/TW_ReplicationTesting.c

GitHub

Contribute to TrainWreckers/Extraction development by creating an account on GitHub.

#

could be a case where not specifying storage component is duplicating. Going to try specifying and see if it clears it up

undone gyro
#

Yeah maybe

#

I will take a look next week

rigid pecan
#

All good. I'll make like a dwarf and keep digging into this 🤣 . Enjoy your weekend!

rigid pecan
#

It requires both specifying storage component AND deposit purpose, otherwise if I don't specify storage component it duplicates.

tight panther
#

Any news on this? Got pretty much the same behaviour as described by using TryInsertItem or InsertItem methods with specified storage, but without specified storage purpose

tight panther
#

Setting the slot id to 0 instead of leaving it on the default -1 seems to fix the issue. No idea if this will have side effects though

rigid pecan
#

You have to do both, otherwise it dupes

undone gyro
#

Sorry guys, I'm on something else right now, but I have this bookmarked

#

This issue arise both with TrySpawnPrefab and TryInsertItem ?

tight panther
#

Yes, both resulted in the same behaviour for me. The only temporary fix i found was the one stated above, setting slot id to 0. From testing it also seemed like the doubled item acted as a reference to the actual item, since i could drop the actual item, have someone pick it up, use it on my end (map) which resulted in it being pulled out of their inventory again

undone gyro
#

Ok, thanks, I will check then

tight panther
#

No matter what I do now, it dupes the item. It worked just fine yesterday and now it's bugged. Tried all methods, spawning using GetGame().SpawnEntityPrefab() and TryInsertItem, EStoragePurpose.PURPOSE_DEPOSIT, TrySpawnPrefabToStorage. None seem to add a single item. Every function seems to add an additional "broken" item on the client side

rigid pecan
# tight panther No matter what I do now, it dupes the item. It worked just fine yesterday and no...

Interesting indeed. I am glad to at least have someone else able to reproduce this. Though curious why the approach I took didn't work in your case for fixing it.

https://github.com/TrainWreckers/Extraction/blob/main/Scripts/Game/Components/SCR_TW_RandomInventoryComponent.c#L105-L111

GitHub

Contribute to TrainWreckers/Extraction development by creating an account on GitHub.

tight panther
#

Server adds 2 items, client none. Checked using Peer Tool logging

#

Result is 4 items inside the inventory on the clientside. When I leave the game, causing the inventory to be serialized again, it also only writes those 2 items

rigid pecan
#

In my case, it was the server adding 1 item but clients would see 2. BUT only 1 of the items were actually usable. They'd get the duplicated item as unusable, couldn't do anything with it.

#

Whatever server added - clients would see double

Server 5 -- clients 10

tight panther
#

Don't know about the usable items part, will check for other items on my end. But for me it was the magazines duplicating

rigid pecan
#

At first I thought it was just magazines because that was the most noticible. It was everything getting duped. Depends on the container and whether the server was successful in adding that item to the destination container

tight panther
#

Ah yea, i know what you mean by not usable. Yea they're broken for me too, can't interact with them unless they have some scripted functionality (like the map)

rigid pecan
#

OH... interesting

#

Non scripted items only see that behavior when duped... interesting

#

For shiggles, I made it so a container had 10000 weight and volume capacity. Made it easier to visually test adding items. Perhaps I should follow another devs advice and write a mockup/test mod to help with duplicating this bug. Haven't had the time to do it just yet

#

holidays where I'm at

tight panther
#

One limitation I have however is I need to spawn the entities before inserting them into the inventory since TrySpawnPrefabToStorage doesn't have access to the Entity in the callback (setting mag ammo count after the Entity is spawned)

#

I did try the method but it still results in more items being spawned than there should

rigid pecan
#

Yeah, if you're trying to set ammo count you need that reference. Nice quality of life would be outputting a reference to spawned entity when using the TrySpawn variant

tight panther
#

Only thing I really need is the IEntity reference inside the ScriptedInventoryOperationCallback

#

Then I could just create a custom callback managing the ammo. Actually wondering though, since it seems that some of BIs logic uses callbacks to add items to storages (atleast from what i can tell from quickly looking at it), if it could be that spawning the entity doesnt properly initialize its' storage components directly

rigid pecan
#

oh crap I didn't realize it supported a callback

tight panther
#

Yea I never really looked too much into it either

#

Gonna try using those callbacks, but I doubt it'll have any effect on adding items to the clothings' storage component

tight panther
#

Yea, using callbacks doesnt work either. It seems as if there is something going wrong in the in-engine replication for the storage item inserts

#

Gonna wait for an answer for now ^^

rigid pecan
tight panther
#

Quick question @rigid pecan , are you using a custom respawn logic in your gamemode?

rigid pecan
#

No, I was trying to figure out how to do that but am using the SpawnPoint logic where players can pick their spawn position on the map

undone gyro
#

Quick question, when do you spawn your items? Is it during loading of the world ?

#

It is still weird, because we are using TrySpawnPrefabToStorage in vanilla, when you take things from arsenal, so it would mean we would see them duplicated

tight panther
# undone gyro It is still weird, because we are using TrySpawnPrefabToStorage in vanilla, when...

I fiddled around with it in a new addon yesterday, where the issue unfortunately didnt arise. After copying the logic to my current addon i still see the same behaviour.

Starting to wonder if it could be my spawn logic or another issue with prefabs. I had spawned the m16 prefab with the scope while testing and somehow the GetPrefabName function for it always returned an empty string until i placed a new one

tight panther
#

In my test addon i have pretty much exactly the same setup inventory loading wise, they just differ in terms of what happens before the loadout is requested / spawned

#

At this point it could be anything. I replaced the spawn logic, so I essentially have exactly the same setup used in the testing addon, yet I still get double the items.

#

Gonna try to migrate my scripts to another addon. No idea if i can make it today, but I am starting to think this could be a WB bug

undone gyro
#

I see. I will try the OnPlayerSpawned event on gamecode and spawn some stuff there

#

It could be maybe, because when he spawns, it transfer the ownership between server and the player, and maybe this could cause some issue. Can you try to do just a CallLater there for like 10 seconds, just to be sure 😄

tight panther
#

Alright, gonna try that out real quick

tight panther
#

I found the issue!

#

It seems like the BaseInventoryStorageComponent is not fully initialized / Rpl Ownership hasnt been transferred properly when the clothing item is equipped. I waited 1 second after equipping the pants, then called the mag add method, which resulted in only one mag being added

#

Makes me wonder; does the game method SpawnEntityPrefab wait for components to be initialized?

undone gyro
#

I see, and if you do the inverse, like mag in pants, and then pants ?

#

I was expecting something like that, you give ownership, and it takes, time and somehow you got two. Did you tried to connect another client afterwards, does he get also two of them ?

tight panther
tight panther
undone gyro
#

Can you show me some easy script to reproduce ?

tight panther
tight panther
#

While I still didnt manage to reproduce this issue outside my main project, I did some further testing. It seems that setting CallLater delay to 0 is enough for the clientside to not dupe the storage items. I will try to isolate the character storage and loading part in the coming days so it can be used for testing.