Increment of 0 by 5 equals 5 sometimes 10. Is this a race condition problem? How can I solve this?

It’s a bit difficult to assess because I don’t have a very good picture of the actual inventory system. Namely, I don’t know what FStorageInfo / FSlot look like and I don’t know the function bodies of Add / TryAddToEmptySlot / Try AddToUsedSlot.

If you can add those that might help diagnose the issue a bit; however, the one thing that I did notice in your log screenshots is that the the 5 - 5 and 10 - 5 logs take different code paths. When it’s 5 - 5 you are using TryAddToEmptySlot, when it’s 10 - 5 you are using TryAddToUsedSlot. From the source code I’ve seen, this seems correct, since when it’s 10 - 5 you’re adding 5 to a slot that already has 5 items. Assuming that holds true whenever the issue occurs, the first two places I would check:

  1. Make sure TryAddToUsedSlot isn’t doing any accidental state mutation.
  2. Make sure the storage isn’t somehow maintaining its state between play sessions. If you are dynamically creating that USlotStorage at runtime, (e.g., in PostInitializeComponents or BeginPlay), then you should consider marking the UPROPERTY with Transient. By default all UPROPERTY fields are included in serialization, which isn’t something you usually want for dynamically constructed UObjects.
1 Like