Search Unity

Where can I find documentation about deprecated functions?

Discussion in 'Scripting' started by Lalo, Sep 2, 2011.

  1. Lalo

    Lalo

    Joined:
    Jan 4, 2010
    Posts:
    21
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If it's not in the docs, don't use it. Anything not in the docs can be removed or changed at any time.

    --Eric
     
  3. bdev

    bdev

    Joined:
    Jan 4, 2011
    Posts:
    656
    GetChild lets you get a child by its index. I'm guessing the reason this is not documented or completely supported is because its very destructive code.

    Say you had:

    for( var i : int = 0; i < transform.childCount; i ++ ) Destroy( transform.GetChild(i); );

    You would probably end up crashing as calling destroy will not immediately remove the child list so the loop will run forever. Even if it did though it still would be incorrect because you'd be modifying the list while iterating.

    So if you need to iterate children they do not want you to do any sort of direct access by index. and it would look like this:

    for (var child : Transform in transform) Destroy(child);
    but again i dont know that that even is safe.
     
  4. Lalo

    Lalo

    Joined:
    Jan 4, 2010
    Posts:
    21
    Thank you for your answers.

    I have one parent with a lot of children, every child has a common name, but I use a random index in order to get one random child [0...n], for example with GetChild(0) I get the first one.

    Then I use its position and rotation in order to create a new object with that information, delete just the GetChild(0) and attached the new object with the original parent, same name but different index.

    So far everything is OK, but I want to know more about deprecated functions.

    Whatever, Unity 3D does a great effort in order to give to us a great indie tool.

    Lalo
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Deprecated functions, those that once used to be supported officially, will normally give you a warning in Unitys console directly normally as they have the corresponding attribute set. GetChild just never was supported officially it seems though always present from what I recall.

    Which raises the question on why GetChild is still not officially, as UT hasn't implemented indexed child access for Transform either, only the enumerator based access (this means you can use for( var t:Transform in transform) to go through all childs)
     
    Last edited: Sep 5, 2011
  6. bdev

    bdev

    Joined:
    Jan 4, 2011
    Posts:
    656
    Agree'd with dremora. These are below deprecated and you should not even use them as at unity's whim leaving you screwed. In reality though these functions will most likely not go away until unity decides to actually make some hard decisions and remove functions like these which people may be using because they are there.

    On the other hand maybe some day they will fully support it officially once all the bugs are fixed with it. But that still leaves you using code which the backend of may drastically change making your program somewhat in limbo.

    Its not at unity's interest to document things that they feel are destuctive or otehrwise bad and its not in your intrest to use them. If you must using a get child by index which is basically what this function does do something like:

    static function GetChildByIndex(transform : Transform, int index :int ) :Transform {
    for( var child : Transform in transform ) { if (index -- <= 0) return child; }
    // too far out
    return null;
    }

    but do note that probably the reason GetChild is not fully supported is because children most likely are not added to the end of the list but inserted / sorted some other way.
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    My assumption goes along a similar line. The reason that there is no indexed child access is cause you don't need it. Either you want a specific child, then you use FindChild, or you want to do something on all and use the enumerator.
    Doing something on a "random" one is extremely rare and if really required, you would "number name" the childs and then just use FindChild(Random.Range(0,childCount).ToString()) or something alike

    That or you would actually have a manager that feeds an array and random access that one, cause GetChild likely does enumerate too and then give you the i-th element, so basically "nightmare performance"
     
  8. TheCasual

    TheCasual

    Joined:
    Sep 30, 2010
    Posts:
    1,286
    I dont think i actually ever seen someone actively seeking the use of deprecated methods o_O, lol - nice, i like it. Im so ass backwards most of the time , i shoulda thought of that , they might actually work, unlike most of my code , haha.