Forum rules - please read before posting.

Object reference not set to an instance of an object?

This hasn't been asked, but what's causing this error?
NullReferenceException: Object reference not set to an instance of an object AC.Char.MoveUpdate () (at Assets/AdventureCreator/Scripts/Character/Char.cs:1044) AC.Char._LateUpdate () (at Assets/AdventureCreator/Scripts/Character/Char.cs:570) AC.StateHandler.LateUpdate () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:432)

Comments

  • This'll occur if you don't have a MainCamera, or your MainCamera is not attached to a GameCamera. The next update will remove this error in these circumstances.

  • An Object is an instance of a Class , it is stored some where in memory. A reference is what is used to describe the pointer to the memory location where the Object resides. The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs. To prevent the error, objects that could be null should be tested for null before being used.

    if (mClass != null)
    {
    // Go ahead and use mClass
    mClass.property = ...
    }
    else
    {
    // Attempting to use mClass here will result in NullReferenceException
    }

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.