#Random Inventory Repl/Desync
1 messages · Page 1 of 1 (latest)
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
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
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.
Still duplicates with TrySpawnPrefab
hmmm 🤔
(background is authority), front is peer tool
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.
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
- Spawn an AI, specifically add and equip backpack. Then insert a magazine
- Spawn an AI, do the random stuff
- 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
could be a case where not specifying storage component is duplicating. Going to try specifying and see if it clears it up
All good. I'll make like a dwarf and keep digging into this 🤣 . Enjoy your weekend!
gotta specify purpose of Deposit.... that fixed it. Wild.... lol. It was set to ANY before.
It requires both specifying storage component AND deposit purpose, otherwise if I don't specify storage component it duplicates.
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
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
I have it fixed by setting the purpose to deposit
You have to do both, otherwise it dupes
Sorry guys, I'm on something else right now, but I have this bookmarked
This issue arise both with TrySpawnPrefab and TryInsertItem ?
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
Ok, thanks, I will check then
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
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.
Yea i dont know either. Using the same function results in all spawned prefabs being doubled on clientside
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
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
Don't know about the usable items part, will check for other items on my end. But for me it was the magazines duplicating
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
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)
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
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
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
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
oh crap I didn't realize it supported a callback
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
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 ^^
That was what I was thinking as well
Quick question @rigid pecan , are you using a custom respawn logic in your gamemode?
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
Next major update, you will have a way
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
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
My current setup is I have a menu open before any player is spawned. Once the player is done with the selection, the base loadout is requested and the player is spawned. After that i catch the spawn finalize event from the GameMode to spawn a pants, and a magazine into the inventory.
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
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 😄
Alright, gonna try that out real quick
Used calllater and it still spawns double the amount. Super awkward. Gonna try migrating the scripts to another addon now lol
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?
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 ?
This didn't work either. It just seems like the BaseInventoryStorageComponent takes time to initialize and handle ownership
Didnt test it in depth but the issue remained, yes
Can you show me some easy script to reproduce ?
I tried to create one yesterday, but it was entirely different behaviour. Also cannot share the addon since it has external dependencies. Gonna try to get the test addon to reproduce that behaviour and then upload it to github
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.