Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Asset duplication not solved by making the asset addressable

Discussion in 'Addressables' started by Stephanommg, Sep 18, 2023.

  1. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    This is the overview of my setup:
    I have a starting scene (MainMenu) in the player build, which points to another scene (Forest), which is an addressable. This scene is loaded as an addressable.

    Forest has a Player prefab, which has an Animator pointing to an asset animator controller. Forest has also the SceneControl prefab, which points to an ScriptableObject (GameDB), which (indirectly through some data structures) points to the same AnimatorController mentioned early.

    Somewhere in the code, both references to the AnimatorController (from the Player and GameDB) are compared. The comparison returns true (i.e., are the same) in the editor but returns false in the player build.

    So this suggests that the AnimatorController is being duplicated. But I marked it as addressable, tested, and same result. I also tried making all the chain up as addressable (i.e., GameDB, Player prefab, SceneControl prefab), and still same result. This is the first and main problem.

    So I started to do basic addressable tests in a different project, to see if I am getting things right, but things went worse since I couldn't reproduce the problem there. There, the references are always returning true. Even if I make 2 prefabs in different addressable groups (this is even another (simpler) test), both pointing to the same non-addressable asset, comparing both references returns true, but should return false since they were supposed to be duplicated.

    So I am a little lost here about what can be possibly causing both problems.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,849
    Use the Analyse window to find duplications.

    Remember anywhere you have an addressable asset referenced in a non-addressable scene, that results in a duplication.

    Usually this means all your scenes need to be addressable alongside the assets, with a non-addressable bootstrap scene as the only one in your build list that kick starts everything.
     
  3. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    I used the analyse window and it showed the AnimatorController as an unsolvable duplication, but I don't understand why. The scene is addressable as well as everything in the chain of references from the scene to the controller.
     
  4. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    Anyone else? This is happening to all my scriptable objects too. All of them are marked as addressable.
     
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,849
    Something along the chain is non-addressable causing these duplications, it's really the only reason why this happens.

    This is why I don't really bother with the 'making assets addressable' on an individual basis. Instead I organise my asset folders to match my group layout, and make said entire folders addressable. Thus everything is more or less automatically made addressable, and thus I never run into asset duplication.
     
    Apex_Dev_03 likes this.
  6. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    Thank you for the answers.

    If you mark a folder as addressable, all containing files and folders are also addressable? Is this true for all group packing modes?

    As for the mentioned ScriptableObject problem, there were 2 things causing it. 1) The starting scene was not addressable and it had references to the SO's. So I created a scene whose purpose is only to load the real first scene. It still didn't work, because of the second problem: 2) Unity Editor seems to act as a player so it duplicates things too. So it works in the build not not in editor even with Play Mode Script = Use Existing Build. This also solved the OP problem.
     
  7. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,849
    Everything down the chain of files is addressable, unless any assets within this heirarchy are in a Resources folder, or have been specifically assigned to another group.

    What duplicates assets is when assets are built. It's not a behaviour of the editor or a runtime player, just how your addressable groups are organised and built.

    By default, in the editor, assets are loaded via asset database, and no duplication issues should occur.

    Also:
    The Unfixable Analyse rules don't mean that they 'can't be fixed at all', just that Addressables can't automatically fix them. They require manual work to fix. Just an FYI there.
     
    Stephanommg likes this.
  8. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    But if it is in another group then it is an addressable. You mean the case were this other group is not included in build? Then these assets are also out of the build even if they are inside the folder marked as addressable in the other group.

    I tested this the following way. I had a group (DB) with all ScriptableObjects inside the folder GameDBs. Then, I unchecked include in build for group DB and created group DB2 and placed GameDBs folder inside it. Tested the game and the SOs were duplicated.
     
  9. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,849
    I mentioned nothing about 'not including in build' so I have no idea where you got that from. An asset is either in an addressable group, or it's not. I just provided an easy way to include large amounts of assets in a group without having to manually assign them all.

    I'm not sure what you're expecting here. If you're baking assets into two different groups... well no wonder they're duplicated.

    They should only belong to one group.
     
  10. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    72
    And I didn't say you mentioned it.

    One group was not included in the build so there is no sense that this group caused a duplication. I just wanted to test if adding the entire folder would make all children addressable and by consequence not duplicated.