- Home /
The question is answered, right answer was accepted
BCE0048: Type 'UnityEngine.Component' does not support slicing.
Hi!
After converting an older script from Unity 4 to 5 (ThirdPersonSimpleAnimation.js, I obtained it from Unity from somewhere, should be script everyone at least at some point had access to) I get a compiler error:
"BCE0048: Type 'UnityEngine.Component' does not support slicing."
The line where I get this error is
animation["run"].normalizedSpeed = runSpeedScale;
I tried
(animation["run"] as AnimationClip).normalizedSpeed = runSpeedScale;
but that doesn't work either, same message. Anyone an idea?
Slicing error normally happens when you are trying to assign a lone element of a multi element variable of some kind. It usually requires making a temporary variable modifying it and copying it back in.
Is that a Legacy Animation call there?
I'm not even sure Unity 5 still supports Legacy. Does it?
When I saw this, I was sure this would solve it http://answers.unity3d.com/questions/695716/bce0048-type-object-does-not-support-slicing-4.html
So I made it like that
((animation as Array)["run"] as AnimationClip).normalizedSpeed = runSpeedScale;
But now I get
"The best overload for the method 'Array.get_Item(int)' is not compatible with the argument list '(String)'."
Answer by softrare · Mar 04, 2015 at 08:37 PM
Just found it
(animation as Animation)["run"] as AnimationClip).normalizedSpeed = runSpeedScale;
and Unity 5 conversion process just after that made it to
((GetComponent.<Animation>() as Animation)["run"] as AnimationClip).normalizedSpeed = runSpeedScale;
BTW what also works is
GetComponent.<Animation>()["run"].normalizedSpeed = runSpeedScale;
;)
how can that be made on this line?: (it's the same error)
GetComponent.<AudioSource>().clip = footstep [Random.Range(0, footstep.length)];
Follow this Question
Related Questions
How to change camera on trigger enter unity 5 1 Answer
Turn Off Capsule Collider via JavaScript 2 Answers
Unity 5.3 Monodevelop JS Not Checking for Errors or Auto-Completing/Suggesting (C# fine) 1 Answer
Caching Transform Javascript Help 0 Answers
I can't edit my animation or play my other animation 0 Answers