Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

[SOLVED] Hash IDs not working on play

Discussion in 'Scripting' started by rulan, Feb 1, 2019.

  1. rulan

    rulan

    Joined:
    Jun 20, 2013
    Posts:
    9
    Last edited: Feb 1, 2019
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Probably need to see some code. Is HashIDs a public property of Main_PBC? And did you drag a reference to it into the slot in the inspector? Or are you finding it via GetComponent() ?
     
  3. rulan

    rulan

    Joined:
    Jun 20, 2013
    Posts:
    9
    Sure, HashIDs is private right now, I can share the hashID.cs and the Main_PBC.cs
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Please use code tags in the future:
    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Diagnostics;
    6. using System.Runtime.CompilerServices;
    7. using UnityEngine;
    8.  
    9. namespace PBC
    10. {
    11.     public class Main_PBC : MonoBehaviour
    12.     {
    13.         private sealed class _DoExecuteScripts_c__Iterator1 : IEnumerator<object>, IEnumerator, IDisposable
    14.         {
    15.             internal int _PC;
    16.  
    17.             internal object _current;
    18.  
    19.             internal Main_PBC __f__this;
    20.  
    21.             object IEnumerator<object>.Current
    22.             {
    23.                 get
    24.                 {
    25.                     return this._current;
    26.                 }
    27.             }
    28.  
    29.             object IEnumerator.Current
    30.             {
    31.                 get
    32.                 {
    33.                     return this._current;
    34.                 }
    35.             }
    36.  
    37.             public bool MoveNext()
    38.             {
    39.                 uint num = (uint)this._PC;
    40.                 this._PC = -1;
    41.                 switch (num)
    42.                 {
    43.                 case 0u:
    44.                     this._current = new WaitForFixedUpdate();
    45.                     this._PC = 1;
    46.                     return true;
    47.                 case 1u:
    48.                     this.__f__this.moveClass.MoveCharacter(this.__f__this.nPC, this.__f__this.suspendMouse);
    49.                     if (this.__f__this.footIK)
    50.                     {
    51.                         this.__f__this.footIK.DoFootIK();
    52.                     }
    53.                     if (this.__f__this.mouseAimScript && !this.__f__this.nPC)
    54.                     {
    55.                         this.__f__this.mouseAimScript.DoAim(this.__f__this.moveClass.gravity_Hat, this.__f__this.moveClass.platformDeltaAngle, this.__f__this.footIK.Grounded, this.__f__this.suspendMouse);
    56.                     }
    57.                     if (this.__f__this.cameraAnchorScript)
    58.                     {
    59.                         this.__f__this.cameraAnchorScript.MoveCamera();
    60.                     }
    61.                     if (this.__f__this.userCustomIK)
    62.                     {
    63.                         this.__f__this.userCustomIK.DoCustomIK();
    64.                     }
    65.                     this.__f__this.ragdollControl.DoRagdollControl();
    66.                     this.__f__this.animFollow.AfterIK(this.__f__this.moveClass.acc, this.__f__this.moveClass.deltaMouseRotation, this.__f__this.moveClass.effectiveUpLerped2, this.__f__this.moveClass.gravity, this.__f__this.moveClass.tiltPivot);
    67.                     if (this.__f__this.weaponAnimFollow)
    68.                     {
    69.                         this.__f__this.weaponAnimFollow.DoWeaponAnimFollow();
    70.                     }
    71.                     this._PC = -1;
    72.                     break;
    73.                 }
    74.                 return false;
    75.             }
    76.  
    77.             public void Dispose()
    78.             {
    79.                 this._PC = -1;
    80.             }
    81.  
    82.             public void Reset()
    83.             {
    84.                 throw new NotSupportedException();
    85.             }
    86.         }
    87.  
    88.         private Animator animator;
    89.  
    90.         private MoveBaseClass_PBC moveClass;
    91.  
    92.         private UserCustomIK_PBC userCustomIK;
    93.  
    94.         private HashIDs_PBC hashIDs;
    95.  
    96.         private GetWASD_PBC getWASD;
    97.  
    98.         private AnimFollow_PBC animFollow;
    99.  
    100.         private RagdollControl_PBC ragdollControl;
    101.  
    102.         private SeeAnimatedMaster_PBC seeAnimatedMaster;
    103.  
    104.         [HideInInspector]
    105.         public AbstractFootIK_PBC footIK;
    106.  
    107.         [HideInInspector]
    108.         public WeaponAnimFollow_PBC weaponAnimFollow;
    109.  
    110.         [HideInInspector]
    111.         public MouseAim_PBC mouseAimScript;
    112.  
    113.         [HideInInspector]
    114.         public CameraAnchor_PBC cameraAnchorScript;
    115.  
    116.         private Renderer ragdollRenderer;
    117.  
    118.         [SerializeField]
    119.         private bool destroyWhenDead;
    120.  
    121.         public bool nPC;
    122.  
    123.         private bool userNeedsToFixStuff;
    124.  
    125.         [HideInInspector]
    126.         public float realCharacterScale = 1f;
    127.  
    128.         [HideInInspector]
    129.         public bool suspendMouse;
    130.  
    131.         private void Awake()
    132.         {
    133.             this.userNeedsToFixStuff = !this.WeHaveAllTheStuff();
    134.             this.userCustomIK = base.GetComponent<UserCustomIK_PBC>();
    135.             this.seeAnimatedMaster = base.GetComponent<SeeAnimatedMaster_PBC>();
    136.         }
    137.  
    138.         private void Update()
    139.         {
    140.             if (this.userNeedsToFixStuff || this.ragdollControl.stayDown2)
    141.             {
    142.                 return;
    143.             }
    144.             this.getWASD.DoGetWASD(this.nPC, this.suspendMouse, this.footIK.Grounded);
    145.             this.moveClass.DoMoveClassUpdate(this.nPC);
    146.             this.animator.SetBool("nPC", this.nPC);
    147.         }
    148.  
    149.         private void FixedUpdate()
    150.         {
    151.             if (this.userNeedsToFixStuff)
    152.             {
    153.                 return;
    154.             }
    155.             if (!this.ragdollControl.stayDown2)
    156.             {
    157.                 base.StartCoroutine(this.DoExecuteScripts());
    158.             }
    159.             else
    160.             {
    161.                 if (this.destroyWhenDead && !this.ragdollRenderer.isVisible)
    162.                 {
    163.                     UnityEngine.Object.Destroy(base.transform.root.gameObject);
    164.                 }
    165.                 this.ragdollControl.stayDown2 = this.ragdollControl.stayDown;
    166.             }
    167.         }
    168.  
    169.         private IEnumerator DoExecuteScripts()
    170.         {
    171.             Main_PBC._DoExecuteScripts_c__Iterator1 _DoExecuteScripts_c__Iterator = new Main_PBC._DoExecuteScripts_c__Iterator1();
    172.             _DoExecuteScripts_c__Iterator.__f__this = this;
    173.             return _DoExecuteScripts_c__Iterator;
    174.         }
    175.  
    176.         public void MoveParent()
    177.         {
    178.             Vector3 vector = base.transform.position - base.transform.parent.position;
    179.             base.transform.parent.Translate(vector, Space.World);
    180.             base.transform.Translate(-vector, Space.World);
    181.             this.ragdollControl.transform.Translate(-vector, Space.World);
    182.             if (this.cameraAnchorScript)
    183.             {
    184.                 this.cameraAnchorScript.transform.Translate(-vector, Space.World);
    185.             }
    186.         }
    187.  
    188.         private bool WeHaveAllTheStuff()
    189.         {
    190.             if (!(this.moveClass = base.GetComponent<MoveBaseClass_PBC>()))
    191.             {
    192.                 UnityEngine.Debug.LogWarning("No script AdvancedMoveScript on " + base.name + "\n");
    193.                 return false;
    194.             }
    195.             if (!(this.getWASD = base.GetComponent<GetWASD_PBC>()))
    196.             {
    197.                 UnityEngine.Debug.LogWarning("No script getWASD on " + base.name + "\n");
    198.                 return false;
    199.             }
    200.             if (!(this.animFollow = base.GetComponent<AnimFollow_PBC>()))
    201.             {
    202.                 UnityEngine.Debug.LogWarning("No script AnimFollow on " + base.name + "\n");
    203.                 return false;
    204.             }
    205.             if (!(this.ragdollControl = base.transform.root.GetComponentInChildren<RagdollControl_PBC>()))
    206.             {
    207.                 UnityEngine.Debug.LogWarning("No script RagdollControl in children of " + base.transform.root.name + "\n");
    208.                 return false;
    209.             }
    210.             if (this.ragdollControl.master && this.ragdollControl.master != base.transform)
    211.             {
    212.                 UnityEngine.Debug.LogWarning("master of RagdollControl is not set to " + base.transform + "\n");
    213.                 return false;
    214.             }
    215.             if (!(this.ragdollRenderer = base.transform.GetComponentInChildren<Renderer>()))
    216.             {
    217.                 UnityEngine.Debug.LogWarning("No renderer on " + base.name + "\n");
    218.                 return false;
    219.             }
    220.             if (!(this.animator = base.GetComponent<Animator>()))
    221.             {
    222.                 UnityEngine.Debug.LogWarning("No animator on " + base.name + "\n");
    223.                 return false;
    224.             }
    225.             if (!(this.footIK = base.GetComponent<AbstractFootIK_PBC>()))
    226.             {
    227.             }
    228.             if (!this.mouseAimScript)
    229.             {
    230.                 this.mouseAimScript = base.transform.root.GetComponentInChildren<MouseAim_PBC>();
    231.             }
    232.             if (!this.cameraAnchorScript)
    233.             {
    234.                 this.cameraAnchorScript = base.transform.root.GetComponentInChildren<CameraAnchor_PBC>();
    235.             }
    236.             return true;
    237.         }
    238.     }
    239. }
    240.  
    Code (CSharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4.  
    5. namespace PBC
    6. {
    7.     public class HashIDs_PBC : MonoBehaviour
    8.     {
    9.         public int angularSpeedFloat;
    10.  
    11.         public int speedFloat;
    12.  
    13.         public int strafeSpeedFloat;
    14.  
    15.         public int strafeTurnFloat;
    16.  
    17.         public int runWeightFloat;
    18.  
    19.         public int mirrorCrouchBool;
    20.  
    21.         public int roundKickBool;
    22.  
    23.         public int aired;
    24.  
    25.         public int crouch;
    26.  
    27.         public int shooting;
    28.  
    29.         public int gripped;
    30.  
    31.         public int frontTrigger;
    32.  
    33.         public int backTrigger;
    34.  
    35.         public int frontMirrorTrigger;
    36.  
    37.         public int backMirrorTrigger;
    38.  
    39.         public int getupFront;
    40.  
    41.         public int getupBack;
    42.  
    43.         public int getupFrontMirror;
    44.  
    45.         public int getupBackMirror;
    46.  
    47.         public int anyStateToGetupFront;
    48.  
    49.         public int anyStateToGetupBack;
    50.  
    51.         public int anyStateToGetupFrontMirror;
    52.  
    53.         public int anyStateToGetupBackMirror;
    54.  
    55.         private void Awake()
    56.         {
    57.             this.angularSpeedFloat = Animator.StringToHash("angularSpeed");
    58.             this.speedFloat = Animator.StringToHash("speed");
    59.             this.strafeSpeedFloat = Animator.StringToHash("strafeSpeed");
    60.             this.strafeTurnFloat = Animator.StringToHash("strafeTurn");
    61.             this.runWeightFloat = Animator.StringToHash("runWeight");
    62.             this.mirrorCrouchBool = Animator.StringToHash("mirrorCrouch");
    63.             this.roundKickBool = Animator.StringToHash("RoundKickTrigger");
    64.             this.frontTrigger = Animator.StringToHash("FrontTrigger");
    65.             this.backTrigger = Animator.StringToHash("BackTrigger");
    66.             this.frontMirrorTrigger = Animator.StringToHash("FrontMirrorTrigger");
    67.             this.backMirrorTrigger = Animator.StringToHash("BackMirrorTrigger");
    68.             this.getupFront = Animator.StringToHash("Base Layer.GetupFront");
    69.             this.getupBack = Animator.StringToHash("Base Layer.GetupBack");
    70.             this.getupFrontMirror = Animator.StringToHash("Base Layer.GetupFrontMirror");
    71.             this.getupBackMirror = Animator.StringToHash("Base Layer.GetupBackMirror");
    72.             this.anyStateToGetupFront = Animator.StringToHash("Entry -> Base Layer.GetupFront");
    73.             this.anyStateToGetupBack = Animator.StringToHash("Entry -> Base Layer.GetupBack");
    74.             this.anyStateToGetupFrontMirror = Animator.StringToHash("Entry -> Base Layer.GetupFrontMirror");
    75.             this.anyStateToGetupBackMirror = Animator.StringToHash("Entry -> Base Layer.GetupBackMirror");
    76.         }
    77.  
    78.         private void Start()
    79.         {
    80.             Animator component;
    81.             if (component = base.GetComponent<Animator>())
    82.             {
    83.                 component.SetFloat(this.strafeTurnFloat, -0.866f);
    84.                 component.SetFloat(this.runWeightFloat, -0.5f);
    85.             }
    86.         }
    87.     }
    88. }
    89.  
    You need to add this to the Awake in Main_PBC in order to fetch the component:
    Code (CSharp):
    1. hashIDs = GetComponent<HashIDs_PBC>();
     
    rulan likes this.
  5. rulan

    rulan

    Joined:
    Jun 20, 2013
    Posts:
    9
    It worked, thank you, Hash ID is now showing on Main_PBC on Debug Mode.