- Home /
Why wont variable in other GO get assigned?
using UnityEngine;
using System.Collections;
public class StopMovement : StateMachineBehaviour {
public ClickToMove move;
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
//move = move.GetComponent<ClickToMove>();
//move.attackBreak = true;
Debug.Log("Enter");
}
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
//move.attackBreak = false;
Debug.Log("Exit");
}
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log("Update");
move.attackBreak = true;
}
}
Really dont think this has as much to do with the StateMachineBehaviors class as much as it does my accessing other GO from another script.
The variables aren't being assigned and any statement after those lines is ignored?
Any ideas (Sorry for newb issue)
Thanks
So you have another GO with script ClickTo$$anonymous$$ove and now you see "Update" printed to Console, but attackBreak stays false?
No errors or anything in console?
Yes, where ever the reference to the other variable is used, it doesn't change but each Debug Log call will if its called in the function and the reference is commented out.
Answer by GregIven · Dec 13, 2016 at 02:30 AM
The answer was relatively simple, but it was a bit hard to track down. This answer addresses it well. Basically needed to create a reference of the GO that holds the script im referencing and then create an instance of that reference in the start function. Then I can access the GO member variables through the instance.
Your answer
![](https://koobas.hobune.stream/wayback/20220612102302im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to access Vive controllers in a script attached on a simple game object(a cube)? 0 Answers
State Machine Behaviour together with Animation Events 1 Answer
Help! Can't not access the variable linearVelocity of TwistPublisher.cs from another script in Unity 1 Answer
How to get damage variable from another script ? 1 Answer
Check which waypoint is closer 1 Answer