Search Unity

Detecting all scene references an object has

Discussion in 'Scripting' started by joshcamas, Jan 19, 2019.

  1. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,276
    I'm building a tool that intelligently splits scenes into "prefab chunks" during building - however one flaw is if there were scene references between objects that were split up, this clearly would break said references.

    So I need some way of detecting this and packing these together.

    One option is literally scanning through all fields of the object, and any subclasses as well. :') not very fun, but possible. Is there any built in solution with unity? Also, would scanning the scene file be of any use? (since ik id's are used in the scene file)
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    We have a tool that scans for missing object references in the scene. It gets every GameObject/Component in the scene, gets the SerializedObject representation of said object and iterates over all its (serialized) ObjectReference properties.

    If the objectReferenceValue is null, but objectReferenceInstanceIDValue (seems to be undocumented) isn't 0, then it's pointing to a missing object.

    The "built-in solution" for that would be to use SerializedObject, but you have to write what to do with it yourself.
     
    joshcamas likes this.