Search Unity

Implicit downcast question

Discussion in 'Scripting' started by Noxwill, Jun 16, 2013.

  1. Noxwill

    Noxwill

    Joined:
    Apr 16, 2013
    Posts:
    18
    I get a warning

    Assets/meshPartsManager.js(20,18): BCW0028: WARNING: Implicit downcast from 'UnityEngine.Component' to 'UnityEngine.SkinnedMeshRenderer'.

    for this line :

    for (var SkinnedRenderer : SkinnedMeshRenderer in BonedObjects)

    I'm not sure how to explicitly downcast.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use the generic version of GetComponentsInChildren, namely

    Code (csharp):
    1. GetComponentsInChildren.<SkinnedMeshRenderer>();
    which returns a SkinnedMeshRenderer array instead of a Component array.

    By the way, please use code tags for posting code instead of quote tags. Also, you'll find coding to be more consistent and understandable if you follow the convention of using lowercase for variable names. Leave uppercase for functions and classes.

    --Eric
     
  3. Noxwill

    Noxwill

    Joined:
    Apr 16, 2013
    Posts:
    18
    Thank you very much.

    Yeah I thought those were the code tags, oopsie.

    And that isn't my code, I found it on the forums to stitch together different parts of a model (head, chest, etc.) things like that for procedurally generated models.

    I was going to clean it up later because it also uses old functions like SetActiveRecursively which is obsolete now apparently, so I was going to fix it all when everything worked properly (I had weird bugs), and I couldn't figure out how to typecast explicitly to remove these warnings.

    But everything works fine now and I shall clean up the naming conventions (trust me it looks bad to me too), thanks :grin: