Errors with AnimationClip

0

I have these errors on Unity3D in my anime script :

Assets\Assets\Scripts\Assembly-CSharp\AnimBg.cs(14,51): error CS7036: There is no argument given that corresponds to the required formal parameter 'clip' of 'AnimationClipPlayable.Create(PlayableGraph, AnimationClip)'

Assets\Assets\Scripts\Assembly-CSharp\AnimBg.cs(15,5): error CS1061: 'AnimationClipPlayable' does not contain a definition for 'speed' and no accessible extension method 'speed' accepting a first argument of type 'AnimationClipPlayable' could be found (are you missing a using directive or an assembly reference?)

Assets\Assets\Scripts\Assembly-CSharp\AnimBg.cs(16,38): error CS1503: Argument 1: cannot convert from 'UnityEngine.Animations.AnimationClipPlayable' to 'string'

The code is shown below:

using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;

// Token: 0x02000002 RID: 2
[RequireComponent(typeof(Animator))]
public class AnimBg : MonoBehaviour
{
AnimationClipPlayable playable;
    // Token: 0x06000002 RID: 2 RVA: 0x00002058 File Offset: 0x00000458
    private void Start()
    {
        AnimationClipPlayable b = AnimationClipPlayable.Create(this.clip);
        b.speed = this.animspeed;
        base.GetComponent<Animator>().Play(b);
    }

    // Token: 0x04000001 RID: 1
    [SerializeField]
    private AnimationClip clip;

    // Token: 0x04000002 RID: 2
    [SerializeField]
    private float animspeed;
}

Thanks for your help, because I cannot compile the game and I don't know how to solve these errors.

c#
unity3d
asked on Stack Overflow Aug 24, 2019 by laurent47 • edited Aug 24, 2019 by Roxana Sh

1 Answer

0

The problem with this is the line here

AnimationClipPlayable b = AnimationClipPlayable.Create(this.clip);

AnimationClipPlayable.Create takes in two parameters; a playable graph and a clip. Your clip is the second parameter but you need to pass through your playable graph as the first parameter.

Here is the Unity Doc's to explain what that function takes in.

Secondly, AnimationClipPlayable does not contain a variable called speed. If you wish to modify the clips speed, you should use the SetSpeed() function.

b.SetSpeed(animspeed);

Thirdly, Animator does not contain an override function called Play() which takes in a type of PlayableGraph.

It's hard to know what you truly want but if you just want to play an animation on that gameobject, you can do this:

using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;

// Token: 0x02000002 RID: 2
[RequireComponent(typeof(Animator))]
public class AnimBg : MonoBehaviour
{
    // Token: 0x04000001 RID: 1
    [SerializeField]
    private AnimationClip clip;

    // Token: 0x04000002 RID: 2
    [SerializeField]
    private float animspeed;

    private PlayableGraph graph;
    private AnimationClipPlayable playable;
    private AnimationMixerPlayable mixer;
    // Token: 0x06000002 RID: 2 RVA: 0x00002058 File Offset: 0x00000458
    private void Start()
    {
        graph = PlayableGraph.Create();
        AnimationClipPlayable b = AnimationClipPlayable.Create(graph, clip);
        b.SetSpeed(animspeed);

        mixer = AnimationMixerPlayable.Create (graph);
        mixer.ConnectInput (0, b, 0);
        mixer.SetInputWeight (0, 1);

        var output = AnimationPlayableOutput.Create (graph, "output", GetComponent<Animator> ());
        output.SetSourcePlayable (mixer);
        graph.Play ();
    }
}
answered on Stack Overflow Aug 24, 2019 by Ryanas

User contributions licensed under CC BY-SA 3.0