Dev build/Linux: modded loot piles all contain the same items [RESOLVED]

User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: Dev build/Linux: modded loot piles all contain the same items

Post by TheLacus »

pango wrote: Sun Jun 09, 2019 11:36 am Any models replacement mod triggers the bug.
As you suspected, the problem is MeshReplacement.ImportCustomFlatGameobject() resetting the random seed.
I thought we were talking about a sort of hash/id associated to each item instance. Random methods provided by Unity API use a global seed which is supposed to be set right before you use it. If the seed needs to persist, System.Random class can be used instead.

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Dev build/Linux: modded loot piles all contain the same items

Post by pango »

UnityEngine.Random is used in many places in Daggerfall Unity without being (re)seeded.
Maybe System.Random could be used more often instead. UnityEngine.Random provides some nice utility methods like Range(float, float), but that could be fixed (say with extension methods?)...
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Interkarma
Posts: 7247
Joined: Sun Mar 22, 2015 1:51 am

Re: Dev build/Linux: modded loot piles all contain the same items

Post by Interkarma »

It's just the seed being reset by model replacement during layout process. Have merged a fix now to reseed right before generating items. :)
pango wrote: Sun Jun 09, 2019 12:21 pm UnityEngine.Random is used in many places in Daggerfall Unity without being (re)seeded.
The seed is being set at the start of dungeon layout process, of which dungeon loot generation is a part (otherwise the issue would be present even without mods). The problem is just that new code was introduced mid-stream of layout process that flattened seed. Due to the fact that loot can be generated anywhere (indoors, outdoors, dungeons, monsters, shops, etc.), it seems appropriate for this to be re-seeded anytime a loot collection is generated. I'm using current UID (which increments each time an item is generated) multiplied by realtime since startup. That will ensure nicely seeded treasure piles at all times.

There shouldn't be many cases like this. UnityEngine.Random is usually seeded properly at the start of the process before it's used. Loot is just a special case here that isn't part of any one process and needed some extra help.

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Dev build/Linux: modded loot piles all contain the same items

Post by pango »

Glad to know the situation is under control :)
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Interkarma
Posts: 7247
Joined: Sun Mar 22, 2015 1:51 am

Re: Dev build/Linux: modded loot piles all contain the same items

Post by Interkarma »

There's actually still something a bit screwy here. I'm able to reproduce the initial problem despite each loot pile being seeded before generation. It still happens after entering and exiting dungeon multiple time in a row. I'll keep digging on this one.

Edit: Well, found the cause. I was getting a bit too clever for my own good by multiplying the UID by realtimeSinceStartup and overflowing the seed int. I'll rework this one. :)

Locked