Search Unity

Question I need help with changing a Parameter with Script in Editor mode!

Discussion in 'Scripting' started by SaikoArt_Finn, Jan 6, 2021.

  1. SaikoArt_Finn

    SaikoArt_Finn

    Joined:
    Jan 6, 2021
    Posts:
    2
    Hello, i'm currently working on some kind of setup script. its a gesture System for VR where it allows the user of that script to setup a customized gesture system without much Knowledge of setting it up manual. i'm currently working with Blendtrees in which i want to toggle the different animations with a Float Parameter.

    My Problem is: the Test Scrip is working fine in runtime mode, but it's not working in Editor mode (even with ExecuteAlways or ExecuteInEditMode) and it also resets the float parameter to 0 everytime i'm stopping the runtime.

    I'm very new in Scripting and i couldn't find any documentation on how to fix this problem so i hope, i can find some help here! (I'm currently using Unity 2018.4)

    the test Script:
    Code (CSharp):
    1.  
    2. //This is just a test, to not mess up my whole script
    3.  
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7.  
    8. [ExecuteInEditMode]
    9. public class NewBehaviourScript : MonoBehaviour
    10. {
    11.     public float testFloat;
    12.     Animator animator_p;
    13.     //I'll add more Gesture_# once i get this test done
    14.     public type Gesture_1 = new type();
    15.  
    16.     public enum type
    17.     {
    18.         test1,
    19.         test2,
    20.         test3,
    21.        
    22.     };
    23.  
    24.     void Start()
    25.     {
    26.         animator_p = gameObject.GetComponent<Animator>();
    27.    
    28.     }
    29.  
    30.     void Update()
    31.     {
    32.         //each gesture gets different animations on different float values
    33.         switch(Gesture_1)
    34.         {
    35.             case type.test1:
    36.                 {
    37.                     testFloat = 0;
    38.                    
    39.                     animator_p.SetFloat("Gesture1", testFloat);
    40.                 }
    41.                 break;
    42.             case type.test2:
    43.                 {
    44.                     testFloat = 0.5f;
    45.  
    46.                     animator_p.SetFloat("Gesture1", testFloat);
    47.                 }
    48.                 break;
    49.             case type.test3:
    50.                 {
    51.                     testFloat = 1;
    52.  
    53.                     animator_p.SetFloat("Gesture1", testFloat);
    54.                 }
    55.                 break;
    56.         }
    57.     }
    58. }
    59.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Check out the Undo.RecordObject() method to tell the editor a field was changed, such as your testFloat field above.
     
    SaikoArt_Finn likes this.
  3. SaikoArt_Finn

    SaikoArt_Finn

    Joined:
    Jan 6, 2021
    Posts:
    2
    Mhhh i dont think i understand how tho, i tried getting the whole GameObject (with the animator inside) between those brackets and i tried it with the animator itself. but its still the same result. well the script itself does its thing but it doesn't change the parameter within the Animator Controller. only as soon as i go into the runtime again the parameters will be changed. maybe its because the animator is only working during runtime? anyway thanks for the help it was a good idea tho!
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Have you tried recording
    this
    ? That's where your float is located...