Search Unity

Is there a way to trace a ScriptableObject back to its scene?

Discussion in 'Scripting' started by steinbitglis, Aug 16, 2017.

  1. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    I'm trying to create an overview of which ScriptableObjects are being serialized where... but in order to do that, I need to analyze the scenes to identify whether they are being referenced from any of the open scenes.

    My current approach is to create SerializedObjects for each Component and search through the SerializedProperties for object references. The problem arises whenever the scene is realistically sized.

    I'm trying to achieve a comfortable 10 FPS with plenty of leftover frametime for editing. I'm nowhere near that because iterating over ~2 mill. SerializedProperties just takes too much time.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    I'm not 100% sure what you're trying to do, but do you have to iterate all of them? Can you perhaps make a dictionary (or dictionaries) with something unique about each object and then at least you can get at them rapidly, as it will be a hash lookup and scale favorably in search time as the dataset grows larger.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You could turn on text serialization and scan the scene files directly to search for the appropriate GUIDs. I'm not sure it would be any faster, but its worth considering.

    10 FPS? I would have thought this would be a do once job, the kind you can just click start and go take a break until its done. Most computers have plenty of idle time while you sleep.
     
  4. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    @Kurt-Dekker I only have to iterate over those that might suddenly change into a reference to a ScriptableObject. So I'm considering to use some reflection type of analysis to be able to skip SerializedProperties. One or more dictionaries would be involved if I do that.

    @Kiwasi Text serialization is worth considering... but I'm trying to create a completely general tool, so it would impose a big restriction in this situation.

    It's not a do once job. I'm making a live view of all the ScriptableObjects and where they belong. Having to push a button and wait could change the whole mindset of the person working with ScriptableObjects, that's why I'm making it a live view, like the hierarchy window.
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Now I'm curious what you are trying to do. I assumed this was a specific tool for a specific project.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    The Unity Memory Profiler provides the functionality to see from where an object is referenced as well as what references this object has to other objects.

    The Memory Profiler is a generic tool, but it does not feature your "live view", you still have to press a button to capture a snapshot of the current memory.