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
- This topic has 5 replies, 2 voices, and was last updated 1 year, 4 months ago by P.
-
AuthorPosts
-
August 2, 2023 at 4:27 pm #11680::
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.
August 2, 2023 at 7:03 pm #11681::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?
August 3, 2023 at 12:56 am #11687::View post on imgur.com
I’m using the website so I’m still on Part 1. Specifically this part
<code> if (pm.moveDir.x != 0 || pm.moveDir.y != 0) { am.SetBool("Move", true); } else { am.SetBool("Move", false); }</code>
August 3, 2023 at 4:07 am #11688::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.
August 3, 2023 at 9:46 am #11690::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.August 4, 2023 at 3:04 am #11700::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.
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: