Implicit downcast and ArrayList

var animatedObjects : ArrayList = null;

// This gives: BCW0028: WARNING: Implicit downcast from 'Object' to 'AnimatedObject'.
for (var anim : AnimatedObject in animatedObjects)
{
}

Can somebody tell me how to fix this?

That error indicates a downcasting that's not implicity admitted - but your bit of code seems fine. Just a suggestion: try to add #pragma implicit #pragma downcast At the beginning of your code. That would permit downcasting in an implicit way, I think. Let me now...

–

1 Answer

1

Here is a massive investigation of the issue !

In short (1) it can’t be done and (2) one should use List anyway !!

For Javascript noobs: http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F The "List" you should be using instead is "Generic List" aka List< T >, which IS available in Unityscript if you add import System.Collections.Generic; to the top of your script. See link.

–