yet another game-stopping error

I’m getting sick of all these dang errors.

Here is the error:

Assets/Scripts/Character Classes/CharacterGenerator.cs(10,23): error CS1061: Type PlayerCharacter' does not contain a definition for Awake’ and no extension method Awake' of type PlayerCharacter’ could be found (are you missing a using directive or an assembly reference?)

and here’s my code:

public class CharacterGenerator : MonoBehaviour {
	private PlayerCharacter _toon;

	// Use this for initialization
	void Start () {
	   _toon = new PlayerCharacter();
		_toon.Awake(); 
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnGUI() {
		GUI.Label(new Rect(10, 10, 50, 25), "Name");
		_toon.name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.name);
	}
}

The code isn’t finished but the tutorial says that I should have no errors by now, yet I do.

So, if PlayerCharacter did not extend MonoBehaviour it surely would not contain the Awake method from that.

Your fail to post the PlayerCharacter method. But my guess you dont have the “: MonoBehaviour” in the first part of that script.

Some reasons why you might get that error…

  • You’re missing a reference to the assembly that contains the PlayerCharacter class.
  • The Awake method simply does not exist in PlayerCharacter class.
  • The Awake method is not accessible because it is private or protected.
  • You’ve misspelled the method name (case matters).

The bottom line is that the compiler cannot find a method called PlayerCharacter.Awake() in any referenced assembly.

The player character script is this:

using UnityEngine;
using System.Collections;

public class PlayerCharacter : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

But we were told not to put anything in it yet and once again should get no errors anyway

do these two lines appear at the top of the first file?

using UnityEngine;
using System.Collections;

Yes

Oh hell… Awake is not public. you cant call it from another class. It is, however, called automatically when the object is created. Comment out the line and see if it works.

It’s probably a bad design decision to call Awake, it serves a pretty specific purpose. If this is someone else’s code just add this to your PlayerCharacter class - they must have missed it:

public void Awake()
{

}

That helped it. The person who made the tutorial is using an older version of unity so the scripting must’ve been slightly different between then and now.

That’s sort of the case here. Awake is private in Monobehavior and isn’t defined in PlayerCharacter class. However, the author of the code isn’t calling a Monobehavior Awake method, it’s simply a method that he has called “Awake” in his own framework.

I’ve found the tutorial video…

Reading some of the youtube comments, it’s apparent that the author re-edited the video at some point and forgot to include the modifications to PlayerCharacter.cs. It’s clear from the tutorial that PlayerCharacter inherits from BaseCharacter which includes the Awake method. You can see the Awake method code at 9:49 near the end of the video…

398 null reference errors on the filal line, IE this:

	void OnGUI() {
		GUI.Label(new Rect(10, 10, 50, 25), "Name");
		_toon.name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.name);
	}
}

I don’t believe Awake, Start, or Update are virtuals inherited from Monobehaviour. So the way his PlayerCharacter class was written, it’s not that it wasn’t public (although we do typically leave them private) so much as it simply wasn’t there.

There is no name field in that class either. Add the following to PlayerCharacter class:

string name;

or

string name = “_Uninitialized”;

where in the script do I put that?

public class PlayerCharacter : MonoBehaviour {
 
    public string name;

    // Use this for initialization

    void Start () {

    

    }

...
...
...

ok now the errors are just getting stupid:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.TextEditor.ClampPos () (at C:/BuildAgent/work/812c4f5049264fad/Runtime/Export/TextEditor.cs:1184)
UnityEngine.GUI.DoTextField (Rect position, Int32 id, UnityEngine.GUIContent content, Boolean multiline, Int32 maxLength, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/GUI.cs:398)
UnityEngine.GUI.TextArea (Rect position, System.String text) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/GUI.cs:360)
CharacterGenerator.OnGUI () (at Assets/Scripts/Character Classes/CharacterGenerator.cs:20)

and it’s still on the same last lines of code that seems to be the problem…somehow

public string name = “”;

Ok, now the errors are fixed for good (thank goodness…)

when I started programming c++ I never got past errors. I would copy stuff from online or from a book and nothing ever worked. This is because A) I knew nothing about how c++ worked and B) I always had syntax errors that I never knew about because of A)

What ur trying to do is learn Unity before you understand how C# works. :wink:

Eventually, u will get it, its just a harder road.

My suggestion is to find stuff that works and tinker with it. If something with 50 lines of code works, but u want to tweak it, and one line suddenly makes the whole thing stop working. The error is pretty obvious.

Reiterating what has been said; you’re going to want to do a crash course in C#/OOP and possibly some smaller unity projects before you tackle those BurgZerg Arcade tutorials; they’re really good to follow along, but if you lack an understanding as to why he’s doing what’s he’s doing: you’re going to end up with tons of errors that you can’t fix; he tends to revisit errors several lessons into the future, or ignore them entirely/fix them off cam. Just my 2 cents. Good luck.