Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

asset in AssetBundle != asset populated in Inspector

Discussion in 'Scripting' started by Caliber, Aug 12, 2018 at 8:23 PM.

  1. Caliber

    Caliber

    Joined:
    Feb 11, 2018
    Posts:
    20
    Hi

    I use ScriptableObjects (SO) asset files to store item data.
    Enemies carry a list of possible items they can drop, and the list is populated in the Inspector with the item SO asset files.

    When I kill the enemy, they drop an item, and I can pick it up and add it to my inventory. If I already had an identical item in the inventory and run
    if(pickedUpItem == itemInInventory)

    it returns true, as it should. At this point everything works fine.

    Then when I save, I serialize the game data, including references to the SOs in my inventory. To load, I deserialize the data and load SOs from an AssetBundle. So upon loading, my inventory appears to be the same as when I saved, except that all my items in the inventory are populated from an AssetBundle, rather than through the inspector.

    If I at this point kill another mob, pick up an item (referenced in the Inspector) identical to one I already had in the Inventory (from an AssetBundle) and run
    if(pickedUpItem == itemInInventory)

    it returns false.

    Is this behavior expected, or should Unity automatically treat two asset files as the same one, if one is linked in the Inspector and one is loaded from an AssetBundle (meaning I messed something up)?
    If it is expected, what are my options? Do I have to stop linking assets in the Inspector if I need to compare them to assets in an AssetBundle?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    1,571
    Create a system of unique IDs for each item and compare that, so that one instance of the SO matches another instance of the SO when they represent the same thing.

    You could theoretically override the equality operator and compare every single field as well.