Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

askthedev.com Logo askthedev.com Logo
Sign InSign Up

askthedev.com

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Ubuntu
  • Python
  • JavaScript
  • Linux
  • Git
  • Windows
  • HTML
  • SQL
  • AWS
  • Docker
  • Kubernetes
Home/ Questions/Q 39529
In Process

askthedev.com Latest Questions

Asked: May 11, 20252025-05-11T22:14:07+05:30 2025-05-11T22:14:07+05:30

Do I need to group data assets for Addressables when using a ScriptableObject as AssetReference in Unity?

anonymous user

I’m diving into Unity’s Addressables and got caught up with a couple of concerns I hope someone here can clear up. I’m using a **ScriptableObject** as an **AssetReference**, specifically the `AssetReferenceCustomLightmapData` I’ve created. It’s supposed to manage the lightmap data, which includes things like `Texture2D` arrays and `BakedLightProbsData`.

Here’s the tricky part: Do I need to group the actual data assets (like those `Texture2D` textures and the `BakedLightProbsData`) into an Addressables group, or can I just leave the `AssetReferenceCustomLightmapData` on its own? The `CustomLightmapData` holds everything together, and as far as I can tell, no other assets will be needing access to those textures or lightmap data. My gut tells me that since the `ScriptableObject` is the sole access point, I might not need any additional grouping. But Unity’s documentation can be a bit vague on those specifics, so I’d love some input from those who have done this before.

Also, when I load the lightmaps, I’ve noticed it takes about **0.94ms** and generates **34.0KB** of garbage. Upon release, it’s a bit better with **0.27ms** and **15.2KB** of garbage. I can’t help but wonder: could this be related to the line `var data = new LightmapData();` in my `ApplyLightmapData` method? I’m definitely conscious of garbage collection in Unity, and if that line is a culprit, should I be worried about it? Any tips on optimizing this, or am I just overthinking the overhead here?

I guess I’m just looking for some reassurance from the community—whether I’m on the right track or if I need to rethink my approach. Thanks for any details you can share!

  • 0
  • 0
  • 2 2 Answers
  • 0 Followers
  • 0
Share
  • Facebook

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Continue with Google
    or use

    Forgot Password?

    Need An Account, Sign Up Here
    Continue with Google

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. anonymous user
      2025-05-11T22:14:08+05:30Added an answer on May 11, 2025 at 10:14 pm

      It sounds like you’re diving into some pretty interesting stuff with Unity’s Addressables! Let’s break down your concerns.

      Regarding your AssetReferenceCustomLightmapData and whether you need to group the actual data assets (like Texture2D arrays and BakedLightProbsData), it really depends on how you’re planning to use them. Since your ScriptableObject is the main access point and you mentioned that no other assets will need access to those textures or lightmap data, it seems like you could indeed leave it standalone. However, putting them in an Addressables group can make handling dependencies and loading them more organized and cleaner in the long run, especially if you plan to expand your project later.

      As for the garbage generation and loading time you’re seeing, it’s great that you’re being cautious about garbage collection! The line var data = new LightmapData(); in your ApplyLightmapData method could definitely be the reason for some of that garbage. Every new instance creates a bit of garbage that the GC (Garbage Collector) has to deal with. One way to reduce garbage is to reuse the same LightmapData instance instead of creating a new one every time. You can create it once and then modify its properties as needed for each lightmap you apply.

      Optimizing for garbage collection can sometimes feel overwhelming, but you’re definitely on the right track by monitoring it. Tools like the Profiler can help you dive deeper to see what’s actually causing the spikes. Remember, a little bit of garbage isn’t the end of the world, especially if your game runs smoothly overall. Just keep an eye on it and tweak as needed.

      In summary, you might not need the additional grouping for your assets since your ScriptableObject is handling it, but consider how your project might grow. And yes, try reusing instances when you can to minimize garbage. You’re doing great—keep experimenting, and you’ll figure it all out!

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. anonymous user
      2025-05-11T22:14:09+05:30Added an answer on May 11, 2025 at 10:14 pm

      You typically only need to mark the main ScriptableObject (i.e., your AssetReferenceCustomLightmapData) as an Addressable if it’s the single entry point and directly references the dependent assets like Texture2D or BakedLightProbsData. Unity’s Addressables system automatically ensures all referenced dependencies are included and bundled appropriately. Therefore, explicitly putting each texture or baked data asset into its own Addressables group isn’t necessary unless you explicitly want finer control over loading strategies or asset organization. Thus, recognizing your use case—since your custom ScriptableObject acts as the sole access point to all the related lightmap data—you’re correct: it’s sufficient (and typically cleaner) to address just the parent asset and let Unity handle dependency referencing automatically.

      Regarding garbage collection overhead, instances such as var data = new LightmapData(); are indeed likely contributing to the GC allocations you’ve noticed during loading/unloading phases. While 0.94ms and 34KB on loading, and 0.27ms with 15.2KB upon release, is relatively minor overhead in many scenarios, repeated garbage allocations can be troublesome if performance-critical or if frequently repeated (especially in VR or mobile applications). Consider pooling LightmapData objects or reusing existing instances to minimize GC load. However, unless these operations are frequent or performance-critical, you’re likely overthinking this minor overhead. Profiling further and checking if these allocations occur repetitively or heavily at critical moments should clarify if optimization is indeed necessary.

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Sidebar

    Recent Answers

    1. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    2. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    3. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    4. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    5. anonymous user on How can I update the server about my hotbar changes in a FabricMC mod?
    • Home
    • Learn Something
    • Ask a Question
    • Answer Unanswered Questions
    • Privacy Policy
    • Terms & Conditions

    © askthedev ❤️ All Rights Reserved

    Explore

    • Ubuntu
    • Python
    • JavaScript
    • Linux
    • Git
    • Windows
    • HTML
    • SQL
    • AWS
    • Docker
    • Kubernetes

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.