0

I can't seem to get this working, I'm getting an error once opening my c# project file (.exe) and it says "object reference not set to an instance of an object". Here's the line and the one below it.

// Update the actual position

Actor.Position = new Vector3(
                        Actor.PositionToSet.X, 
                        Actor.PositionToSet.Y, 
                        (Math.Round(
                            GetUserStepHeight(
                                Actor.PositionToSet),
                                1)));

Actor.PositionToSet = null;

2 Answers 2

1

The possibility is, either 1. Actor is null or 2. Actor.PositionToSet is null.

To check, either have this:

if(Actor == null){
    System.Console.WriteLine("Actor is NULL");
}

if(Actor.PositionToSet == null){
    System.Console.WriteLine("Actor.PositionToSet is NULL");
}

or use the LINE BY LINE debugger in Visual Studio.

Here is a piece of advice I got years ago:

  1. Think before you code, and build a mental model of the code, then when things break, just reflect on what went wrong without looking at the code.

  2. Unit test your code, make it a standard practice of your coding methodology. This will save you years of debugging time.

Sign up to request clarification or add additional context in comments.

7 Comments

well Actor.PositionToSet is null??
@user2975533 is it NULL? Actor.PositionToSet?
well the line says Actor.PositionToSet = null; on the next line. the main line is the middle one.
@user2975533 are you sure, Actor.PositionToSet is not NULL before you set it to NULL? Just asking, add the lines of code I posted, before the middle one, and tell me what you see.
It's working perfectly now, The file used to close when I went over a certain block in my game and it would crash the "Emulator". Now it just shows loads of lines in the console when i go over one :P Thanks though!
|
0

Please check that Actor or Actor.PositionToSet is not null. That is the only reason.

1 Comment

Sorry but I'm new, how?:S

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.