Search Unity

Question Find missing paramters?

Discussion in 'Scripting' started by Rachan, Dec 25, 2023.

  1. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    781
    Hi there!

    There has anyway to find all missing parameters in all component by code?

    Thanks!
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,647
    What are "missing parameters"?
     
    Bunny83 and Rachan like this.
  3. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    781
    Ok, If I have a component with
    Code (CSharp):
    1. public GameObject Test
    so the Test will be this component parameter right?

    then if this parameter has been assign with some game object, and then that game object has been removed by accidentally or someway, that parameter will show “missing" in the parameter at the slot right?

    that is what I want to find if some component was be like that.
     
  4. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,647
    You can just do a normal null check to see if it has been Destroyed.
     
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,440
    There are thousands of situations where a reference variable is okay to have a null value. Every root object's transform has a parent of null. Most colliders in a scene will have an attachedRigidbody of null. An AudioSource used for multiple sounds typically has a null clip property.

    So, back to the question, what are "missing parameters"? It's a case-by-case situation.

    There are code attributes which people have written (Odin, Naughty Attributes, Inspector Gadgets) to highlight a parameter whenever it is null. That can probably be leveraged in some sort of search system to find cases where there is a parameter with a "required" attribute which is null.
     
  6. The most robust solution is using Odin Validator asset. But it is paid. There are countless free assets on the asset store and on github doing just this. You can also write your own editor scripts, defining your own rules when to alert about missing references and when not to.
     
  7. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    618
    I found it easily worth the cost and there appears to be a 50% discount at the moment.