Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Sep 2011
    Posts
    15

    8 - Lee's Terrain R&D, Pt. 2

    Hi everyone,

    I have just started the watching the MMO classes, and having a blast.

    I am all new to game dev. and programming - I have a film background and can make my way around most post prod. software. So far I have gone through with the Unity Fundamentals, Unity Standard, 3rd pers character sys. and now I am doing the C# classes and the MMO (slow and steady).

    However, I have bumped into a prob I am not managing to see what I have done wrong. Firstly, I am on mac, and using MonoDevelop (would this be an issue?)

    Here is the error messages I am getting:

    Code:
    NullReferenceException: Object reference not set to an instance of an object
    GameManager.Start () (at Assets/_Scripts/GameManager.cs:21)
    NullReferenceException: Object reference not set to an instance of an object
    GameManager.Update () (at Assets/_Scripts/GameManager.cs:28)
    NullReferenceException: Object reference not set to an instance of an object
    GameManager.OnGUI () (at Assets/_Scripts/GameManager.cs:33)
    any help, or pointing me in the right direction would be very much appreciated. Until then I will have to keep doing the C# tutorials which will probably help.

    Any suggestions for a scripting prog that would be useful (mac)?

    thanks a lot,

    kindly
    f
    Last edited by fatgav; 10-06-2011 at 06:13 PM. Reason: added "code" tags

  2. #2
    Join Date
    Aug 2011
    Location
    Kansas
    Posts
    181
    Review your code carefully - make sure you don't have uppercase when it needs lowercase, etc. That's gotten me a few times, especially on GameObject vs. gameObject, etc.

    I went through all those first batch of terrain tutorials a couple weeks ago and they all work (using Visual Studio - but I don't see why MonoDevelop wouldn't work too)

  3. #3
    Join Date
    Sep 2011
    Posts
    15
    cheers OldRod,

    will give it another go before night, if I can't find the bug I'll continue with the scripting tutorial.

    thanks for the input

    f

  4. #4
    Join Date
    Mar 2007
    Location
    Las Cruces, New Mexico
    Posts
    43
    Did you look at the line the exception was thrown at?

    GameManager.Start () (at Assets/_Scripts/GameManager.cs:21)

    That error probably means you are trying to either use an object that hasn't been intialized yet, or an asset that isn't present or wasn't found. You didn't share your code so it's jsut guessing.

  5. #5
    Join Date
    Sep 2011
    Posts
    15
    Hi eibonscroll,

    I removed the GameManager script from my post - wasn't sure if it would be liked, as I followed the class script.

    here it is,

    Code:
    using _CodeBase.DemoFramework;
    using _CodeBase.DemoFramework.Features;
    using _CodeBase.Demos;
    using UnityEngine;
    using System.Collections;
    
    
    public class GameManager : MonoBehaviour 
    {
        public static IDemo Demo { get; private set; }
        
        void awake()
        {
            Demo = new TerrainDemos();
            
            Demo.Awake();
        }
        
        void Start()
        {
            Demo.Start();
        }
        
        void Update()
        {
            MouseLock.HandleMouseCursorLocking();
            
            Demo.Update();
        }
        
        void OnGUI()
        {
            Demo.OnGUI();
        }
        
        void OnApplicationQuit()
        {
            Demo.OnApplicationQuit();
        }
        
    }
    thanks
    f
    Last edited by fatgav; 10-06-2011 at 06:14 PM.

  6. #6
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    Hmmm... strange. I've checked this side by side to mine and the logic seems correct, so I'm guessing that you have a typo here:
    Code:
    Demo = new TerrainDemos();
    Did you really pluralise the TerrainDemo class..? Hope this helps.

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  7. #7
    Join Date
    Sep 2011
    Posts
    15
    Hi Fatgav,

    yeah, I did that typo when I made the first class, so I stuck to it throughout, but that might be it.... will change it throughout the project and see how that holds up.
    cheers

    Edit: changed the 'typo' but to no avail... I have to be missing something...hmmm


    f
    Last edited by fshortt; 10-07-2011 at 02:45 AM.

  8. #8
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    Hmm... you did remember to actually create a game manager object in unity, add it to the scene and attach the script to it..? I really can't think of what else could be wrong...

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  9. #9
    Join Date
    Sep 2011
    Posts
    15
    Quote Originally Posted by fatgav View Post
    Hmm... you did remember to actually create a game manager object in unity, add it to the scene and attach the script to it..? I really can't think of what else could be wrong...
    Hi fatgav, yeah... I am at a loss. I removed it from unity and re-attached it just in case if there was some glitch, also purchased unity pro...
    Think I'll have to start again from the R&D, as the mouselock works perfectly fine...

    I am getting this error when I debug:

    Exception Caught
    "Object reference not set to an instance of an object"

    Instance {System.NullReferenceException: Object reference not set to an instance of an object at GameManager.Update() [0x00005] in...
    base {System.SystemException}
    * The object was used after being disposed.



    So I am wondering if the error is in one of the other scripts, e.g. TerrainPatch.cs ??
    Code:
    using System;
    using System.Collections.Generic;
    using UnityEngine;
    
    namespace _CodeBase.Demos
    {
    	public class TerrainPatch
    	{
    		private List<Vector3> Vertices = new List<Vector3>();
    		
    		public int Size { get; set; }
    		public float Spacing {get; set; }
    		
    		public TerrainPatch(int size, float spacing)
    		{
    			Size = size;
    			Spacing = spacing;
    			
    			//Create the grid
    			CreateGrid();
    		}
    		
    		void CreateGrid()
    		{
    			var index = 0;
    			
    			for (int z = 0; z < Size; z++)
    			{
    				for (int x = 0; x < Size; x++)
    				{
    					Vertices.Add(new Vector3(x * Spacing, 0, z * Spacing));
    					
    					index++;
    				}
    			}
    			
    			foreach (var vertex in Vertices)
    			{
    				GameObject tempGO = GameObject.CreatePrimitive (PrimitiveType.Sphere);
    				tempGO.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
    				tempGO.transform.position = vertex;
    			}
    			
    		}
    	}
    }
    Thanks for the effort guys, very much appreciated.
    Will do the R&D vids again tonight, hope i find the error by doing it over. (a good way to learn -trial and error- lol)

    kindly

    f

  10. #10
    Join Date
    Sep 2011
    Posts
    15
    Found the error!!!

    Thanks guys!


    it was in GameManager script:

    Code:
     void awake()
        {
            Demo = new TerrainDemos();
            
            Demo.Awake();
        }
    void awake() instead of void Awake()

    yay!

    but no spheres - will let you know how it goes, but cheers for all the help
    Edit: All is good, and I got spheres - I had removed it from TerrainDemo to start over... in the end it was the lack of capital A on Awake in GameManager! Again cheers everyone!

    kindly

    f
    Last edited by fshortt; 10-07-2011 at 02:06 PM. Reason: update!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •