So I needed character movement and animation so i watched a YouTube tutorial (
) after finished following the steps I pressed play i got a bunch of errors saying missing hash and i couldn’t move my character because the input manager script wasn’t enable so i enabled it in game i tried walking around and I found out that when i let go of the wasd keys my character doesn’t stop moving in game so i check the code and I’m pretty sure it has to do with awake since the script disables its self after pressing play or am i being stupid sorry for the weird grammar and noob behavior
Did you add Debug.log calls in your scripts to see what methods are running? Note that Awake requires an active gameobject for it to run. Also, if you are getting errors, those errors can stop your code from completely running, which may keep things from behaving correctly. Make sure you address those errors as well.
so sorry about the tags also Im new to using unity and code overall not sure what debug.logs are BUT i did get all the errors fixed so that wasnt the problem and the active game object I’m also kinda confused and still learning about sorry for being oblivious to this stuff
In Unity Debug.Log() prints a message to your console. It’s useful to check if a piece of code runs and to print information about your script to see if the values are what you expect them to be. It’s critical for debugging and will help you solve most of your errors.
Few examples:
using UnityEngine;
public class Debugs : MonoBehaviour
{
public int someValue = 10;
public float someOtherValue = 5.2f;
public string alsoSomething = "hello";
void Start()
{
Debug.Log("Your Message");
Debug.Log("GameObjectName: " + gameObject.name);
Debug.Log("My number: " + 5.2f);
Debug.Log("Also my number: " + someOtherValue);
Debug.Log("First thing: " + someValue + ", second thing: " + someOtherValue + ", last thing: " + alsoSomething + ".");
Debug.Log($"First thing: {someValue}, second thing: {someOtherValue}, lastThing: {alsoSomething}.");
}
}
Would highly recommend the Junior Programmer pathway. I hear it’s great if you’re just starting out in Unity is likely to speed your progress a lot. https://learn.unity.com/pathway/junior-programmer
Well, “scripts” in Unity (more specifically classes derived from MonoBehaviour) are custom components. They need to be attached to a GameObject in the scene. Unity’s component system allows you to create gameobjects in your world which are just empty shells / mediators and act as a socket for components. Components essentially define what that object actually does and how it behaves. An object needs some kind of Renderer in order to show up in the world. There are other components like the Rigidbody component which turns the object into a physics controlled object.
Besides the built-in components there are also our own MonoBehaviour scripts which you can attach to an object to give that object “behaviour”. It’s called MonoBehaviour because we write our behaviours with C# on the managed “Mono” side. Mono is just an open source and cross platform variant of the .NET framework.
So in order for a MonoBehaviour script to do anything, it needs to be attached to an “active” gameobject in the scene. GameObjects can be deactivated in which case they still exist, but don’t do anything. Certain components can also individually be enabled / disabled. To attach a script to a gameobject you just need to drag the script onto the gameobject. You will see the instance in the inspector when you select the gameobject. You can also add components at runtime from code by using AddComponent if necessary. Though it’s common to create predesigned prefabs which you then instantiate into the scene.
So when you add a Debug.Log statement to your Awake method, you will immediately see in the console when you run your game if Awake runs or not.
Note: You can also pass a “context” object to Debug.Log as second argument. This can be any gameobject, component or other engine object. When you then click on the log message in the console, the editor will highlight / “ping” that object in the hierarchy or project view. This can help identifying the actual object you’re dealing with.
alright so I can confirm that the awake function is indeed working through using debug.log and it is attached to a game object but it seems that the . cancel functions aren’t working properly and still have absolutely no idea why