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;
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:
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.
Unit test your code, make it a standard practice of your coding methodology. This will save you years of debugging time.
Please check that Actor
or Actor.PositionToSet
is not null. That is the only reason.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.