Forum begins after the advertisement:


am.SetBool(“Move”), true does not work

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity am.SetBool(“Move”), true does not work

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #11680
    P
    Participant

    Hey there,

    I’m using 20022.3.5f1 for the Unity Version, so I’m not sure if something has changed. For some reason the Boolean “Move” is not triggering when the conditions to move/not move are set.

    I added a Debug.Log(); to check when the boolean changes from true/false but it shows nothing is happening. As a precaution, I just copied the entire code from the website using ctrl + c/v just to be sure that there was nothing wrong with my code (compared to the one I was writing using my own variable naming/formatting).

    Both mine and the code used in the demonstration does not work. I don’t know if it’s because of a Unity version issue or something else. I’ve even tried GameObject.Find, GetComponentInParent, GetComponentInChild just in case somehow it was not finding it there either.

    The animator is attached to the Player gameObject.

    #11681
    Terence
    Keymaster

    Hi P, I doubt it is a Unity version issue. With version changes, you may expect the UI layout to change, or some Unity components to be available or unavailable, but the code largely stays the same.

    If you have copied the code from the blog, then the code shouldn’t be where the issue lies. I reckon that it probably has to do with how your Animator is set up.

    Is the “Move” Boolean you are referring to an Animator Parameter? Could you show me a screenshot of this? Also, which part of the tutorial are you at?

    #11687
    P
    Participant

    View post on imgur.com

    I’m using the website so I’m still on Part 1. Specifically this part

            if (pm.moveDir.x != 0  || pm.moveDir.y != 0)
            {
                am.SetBool("Move", true);
            }
            else
            {
                am.SetBool("Move", false);
            }
    #11688
    P
    Participant

    I couldn’t see how to edit to update my post, so adding to it. When I hit play, if I manually check the “Move” boolean in the animator, it’ll play the animation state, and never turn it off.

    Something is not allowing the SetBool function to work within the script, even though the script is a direct copy and paste of what is written. I’ve double checked with the video as well now.

    The Move bool also does not show up in the inspector on the Player gameObject as well.

    #11690
    Terence
    Keymaster

    Hi P,

    Try adding the highlighted line to your code:

            if (pm.moveDir.x != 0  || pm.moveDir.y != 0)
            {
                am.SetBool("Move", true);
            }
            else
            {
                am.SetBool("Move", false);
            }
            print(am.GetBool("Move"));

    See if this prints the status of the boolean on the Console at every frame.

    If it doesn’t, then that means that the function containing this code is not running, possible because it is misspelled. If I remember correctly, this code should be in Update() correct? Check that the function is spelled correctly.

    #11700
    P
    Participant

    This was exactly the issue! The script was still named NewBehaviorScript because I accidentally closed focus when naming the file, and when I renamed it, it was still referring to itself as NewBehaviorScript. I don’t know why I couldn’t isolate that when I had set up the debug log, clearly I am not isolating all the problems.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: