I am just subtracting one float from another in the tick function and it always crashes!

I am really stumped here. The currentGameTime variable used to be a call to World()->GetRealTimeSeconds which was causing the crash and I thought maybe I am not allowed to call wold static functions from the tick method. So I moved it out to another function within the AActor that gets called fairly often but it’s still crashing. It’s weird because you can see that both variables contain normal looking float numbers in them. So shouldn’t they subtract and assign to my new float holder just fine?

Is this a threading issue? Too many calls to the same variable? I am in over my head on this one. All I need is to know is the time 2 seconds(m_realTimePlayDelay) before the current running game time at the time of the tick.

I don’t know about VisualStudio, but with VSCode it’s often happens that if it shows the error in a certain line, it’s actually in the previous line, IDK why.
In your case the error is a null pointer and line 85 deals with pointers, so maybe look into it instead of line 86 where the error allegedly is.

1 Like

Woooow! That is immensely frustrating!

Yeah, the m_takeDataRecievedAtSplinePointIndex TMap is always the same length as the Spline and I wasn’t doing the ole -1 at the end of the get length method.

I have been having a lot of problems with errors since working in Unreal. Whatever, I guess.

The reason for this is that the return value of the Find function in this case is null; meaning on line 85, lastSplineTime = null;

When you go to initialize currentPlayToTime on line 86, you’re attempting to subtract a nullptr, which is an access violation and thus the error.

To avoid this in the future, check the validity of your variables before performing various operations on them

float lastSplineTime = *someObject.Find();

if (lastSplineTime)
{
    // Do math with lastSplineTime
}

or with pointers

if (lastSplineTime != nullptr)
{
    // Do math with lastSplineTime
}

I am not attempting to subtract a nullptr. That’s why I called it “subtracting floats” in the title and I pinned both of those values in my screenshot so you could see that they aren’t null pointers and are both float values. I am also not doing anything with the return value of line 85 on 86. This seems like a simple error in Unreal’s compilation process or something in Visual Studio. Based on my experience with both Visual Studio and Unreal, I think it’s Unreal’s fault.