Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Parameter does not exist warnings

Discussion in 'Animation' started by DustyShinigami, Jun 16, 2019.

  1. DustyShinigami

    DustyShinigami

    Joined:
    Jan 5, 2018
    Posts:
    529
    I'm currently having issues getting my chest opening animation to work. I've not usually had problems with setting up transitions/parameters like this before, so I'm not sure what's wrong. No matter what parameters I set up, I keep getting warnings when I step into the trigger saying 'Parameter 'chestClosed' does not exist' etc. They're set up in the Parameters list, I've specified my Transitions, I've add the code in the script, so I'm not sure what I'm overlooking. :-\

    OpenChest:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class OpenChest : MonoBehaviour
    6. {
    7.     public bool openChest;
    8.  
    9.     public void OnTriggerEnter(Collider other)
    10.     {
    11.         if (other.gameObject.CompareTag("Player"))
    12.         {
    13.             openChest = true;
    14.         }
    15.     }
    16. }
    PlayerController:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class PlayerController : MonoBehaviour
    7. {
    8.     public Animator anim;
    9.     public float moveSpeed;
    10.     public float jumpForce;
    11.     public bool jumped;
    12.     public bool allowInteract = false;
    13.     public float gravityScale;
    14.     public float knockBackForce;
    15.     public float knockBackTime;
    16.     public float invincibilityLength;
    17.     public Renderer playerRenderer;
    18.     public Material textureChange;
    19.     public Material textureDefault;
    20.     public bool allowCombat;
    21.     public bool allowJump;
    22.     public static bool canMove;
    23.     public GameObject chest;
    24.  
    25.     [SerializeField]
    26.     private HurtEnemy damageEnemy;
    27.     private Vector2 moveDirection;
    28.     private Vector2 moveHorizontal;
    29.     private Vector2 moveVertical;
    30.     private float knockBackCounter;
    31.     private float invincibilityCounter;
    32.     private CharacterController controller;
    33.     private Quaternion targetRot;
    34.     private bool headingLeft = false;
    35.     private Pickup pickupWeapon;
    36.     private OpenChest openChest;
    37.  
    38.     void Awake()
    39.     {
    40.         controller = GetComponent<CharacterController>();
    41.         openChest = chest.GetComponent<OpenChest>();
    42.         //damageEnemy = projectile.GetComponent<HurtEnemy>();
    43.     }
    44.  
    45.     void Start()
    46.     {
    47.         Cursor.visible = false;
    48.         pickupWeapon = FindObjectOfType<Pickup>();
    49.         canMove = true;
    50.         targetRot = transform.rotation;
    51.         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("start_area"))
    52.         {
    53.             allowCombat = false;
    54.             allowJump = true;
    55.         }
    56.         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("hut_interior"))
    57.         {
    58.             allowCombat = false;
    59.             allowJump = false;
    60.         }
    61.         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("start_area 2"))
    62.         {
    63.             allowCombat = false;
    64.             allowJump = true;
    65.         }
    66.         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("level 1, room 1"))
    67.         {
    68.             allowCombat = true;
    69.             allowJump = true;
    70.         }
    71.         if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("level 1, room 2"))
    72.         {
    73.             allowCombat = true;
    74.             allowJump = true;
    75.         }
    76.     }
    77.  
    78.     void Update()
    79.     {
    80.         if (knockBackCounter <= 0 && canMove)
    81.         {
    82.             moveHorizontal.x = Input.GetAxis("Horizontal");
    83.             float moveHorizontalSnap = Input.GetAxis("Horizontal");
    84.             float moveVertical = Input.GetAxis("Vertical");
    85.             //moveVertical.y = Input.GetAxis("Vertical");
    86.             moveDirection = new Vector2(moveHorizontal.x * moveSpeed, moveDirection.y);
    87.             controller.Move(moveDirection * Time.deltaTime);
    88.  
    89.             //Adds character rotation when changing direction horizontally
    90.             if ((moveHorizontal.x < 0f && !headingLeft) || (moveHorizontal.x > 0f && headingLeft))
    91.             {
    92.                 if (moveHorizontal.x < 0f) targetRot = Quaternion.Euler(0, 270, 0);
    93.                 if (moveHorizontal.x > 0f) targetRot = Quaternion.Euler(0, 90, 0);
    94.                 headingLeft = !headingLeft;
    95.             }
    96.  
    97.             //Adds character rotation when changing direction vertically
    98.             /*if(moveVertical.y < 0f && lookingUp || (moveVertical.y > 0f && !lookingUp))
    99.             {
    100.                 if (moveVertical.y > 0f) targetrot = Quaternion.Euler(0, 0, 0);
    101.                 if (moveVertical.y < 0f) targetrot = Quaternion.Euler(0, 180, 0);
    102.                 lookingUp = !lookingUp;
    103.             }*/
    104.  
    105.             transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, Time.deltaTime * 20f);
    106.  
    107.             if (SceneManagement.insideHut)
    108.             {
    109.                 //Adds character rotation when changing direction horizontally, but snaps instead of fully rotating
    110.                 if (moveHorizontalSnap > 0)
    111.                 {
    112.                     transform.eulerAngles = new Vector2(0, 90);
    113.                 }
    114.                 else if (moveHorizontalSnap < 0)
    115.                 {
    116.                     transform.eulerAngles = new Vector2(0, -90);
    117.                 }
    118.                 //To possibly prevent diagonal movement with some control setups, try adding 'else if'
    119.                 //Adds character rotation when changing direction vertically, but snaps instead of fully rotating
    120.                 else if (moveVertical > 0)
    121.                 {
    122.                     transform.eulerAngles = new Vector2(0, 0);
    123.                 }
    124.                 //Use this to make the character face towards the camera.
    125.                 /*else if (moveVertical < 0)
    126.                 {
    127.                     transform.eulerAngles = new Vector3(0, 180);
    128.                 }*/
    129.             }
    130.  
    131.             if (controller.isGrounded)
    132.             {
    133.                 if (allowJump)
    134.                 {
    135.                     moveDirection.y = -1f;
    136.                     //GetKeyDown will require the player to press the button each time they want to jump. GetKey will allow the player to spam the jump button if they keep pressing it down.
    137.                     if (Input.GetKeyDown(KeyCode.KeypadPlus) || Input.GetKeyDown("joystick button 0"))
    138.                     {
    139.                         moveDirection.y = jumpForce;
    140.                         jumped = true;
    141.                     }
    142.                     else if (!Input.GetKeyDown(KeyCode.KeypadPlus) || !Input.GetKeyDown("joystick button 0"))
    143.                     {
    144.                         jumped = false;
    145.                     }
    146.                 }
    147.  
    148.                 if (allowCombat)
    149.                 {
    150.                     if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("joystick button 7") || Input.GetKeyDown("joystick button 1"))
    151.                     {
    152.                         playerRenderer.material = textureChange;
    153.                         anim.SetTrigger("Attack");
    154.                     }
    155.                     else if (!Input.GetKeyDown(KeyCode.Space) || !Input.GetKeyDown("joystick button 7") || !Input.GetKeyDown("joystick button 1"))
    156.                     {
    157.                         playerRenderer.material = textureDefault;
    158.                     }
    159.                 }
    160.                 else if (!allowCombat)
    161.                 {
    162.                     playerRenderer.material = textureDefault;
    163.                 }
    164.  
    165.                 if (allowInteract)
    166.                 {
    167.                     if (SceneManagement.xbox360Controller == 1)
    168.                     {
    169.                         if (Input.GetKeyDown("joystick button 2"))
    170.                         {
    171.                             anim.SetBool("Interact", controller.isGrounded);
    172.                             pickupWeapon.ObjectActivation();
    173.                             allowInteract = false;
    174.                         }
    175.                     }
    176.                     else if (SceneManagement.ps4Controller == 1)
    177.                     {
    178.                         if (Input.GetKeyDown("joystick button 0"))
    179.                         {
    180.                             anim.SetBool("Interact", controller.isGrounded);
    181.                             pickupWeapon.ObjectActivation();
    182.                             allowInteract = false;
    183.                         }
    184.                     }
    185.                     else
    186.                     {
    187.                         if (Input.GetKeyDown(KeyCode.Return))
    188.                         {
    189.                             anim.SetBool("Interact", controller.isGrounded);
    190.                             pickupWeapon.ObjectActivation();
    191.                             allowInteract = false;
    192.                         }
    193.                     }
    194.                 }
    195.                 if(openChest.openChest)
    196.                 {
    197.                     anim.SetBool("chestClosed", true);
    198.                     if (SceneManagement.xbox360Controller == 1)
    199.                     {
    200.                         if (Input.GetKeyDown("joystick button 2"))
    201.                         {
    202.                             anim.SetBool("Interact", controller.isGrounded);
    203.                             allowInteract = false;
    204.                             anim.SetTrigger("Open");
    205.                         }
    206.                     }
    207.                     else if (SceneManagement.ps4Controller == 1)
    208.                     {
    209.                         if (Input.GetKeyDown("joystick button 0"))
    210.                         {
    211.                             anim.SetBool("Interact", controller.isGrounded);
    212.                             allowInteract = false;
    213.                             anim.SetTrigger("Open");
    214.                         }
    215.                     }
    216.                     else
    217.                     {
    218.                         if (Input.GetKeyDown(KeyCode.Return))
    219.                         {
    220.                             anim.SetBool("Interact", controller.isGrounded);
    221.                             allowInteract = false;
    222.                             anim.SetTrigger("Open");
    223.                             anim.SetBool("chestOpened", true);
    224.                         }
    225.                     }
    226.                 }
    227.             }
    228.         }
    229.         else
    230.         {
    231.             knockBackCounter -= Time.deltaTime;
    232.         }
    233.  
    234.         moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale * Time.deltaTime);
    235.  
    236.         anim.SetBool("isGrounded", controller.isGrounded);
    237.         //If the character can't move, then the Speed is set to 0. Otherwise it'll use the horizontal input value.
    238.         anim.SetFloat("Speed",
    239.             !canMove
    240.             ? 0f
    241.             : Mathf.Abs(Input.GetAxis("Horizontal")));
    242.  
    243.         //anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));
    244.  
    245.         /*if (interact)
    246.         {
    247.             if (Input.GetKeyDown(KeyCode.Return))
    248.             {
    249.                 anim.SetBool("Interact", controller.isGrounded);
    250.                 FindObjectOfType<Pickup>().ObjectActivation();
    251.                 interact = false;
    252.                 allowInteract = false;
    253.             }
    254.         }*/
    255.     }
    256.  
    257.     public void Knockback(Vector3 direction)
    258.     {
    259.         knockBackCounter = knockBackTime;
    260.  
    261.         moveDirection = direction * knockBackForce;
    262.         moveDirection.y = knockBackForce;
    263.     }
    264. }
    Untitled.png
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,615
    Are you sure that the PlayerController's anim variable is set to the same animator as the one that is in your screenshot?
     
    DustyShinigami likes this.
  3. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,554
    Yeah, my guess is that the script is on the wrong object or on another object with the wrong controller.
     
  4. DustyShinigami

    DustyShinigami

    Joined:
    Jan 5, 2018
    Posts:
    529
    I figured it out last night. I was using the PlayerController's Animator instead of the chest's. :p