GetFirstPhysicsBodyInReach doesn't work

GetFirstPhysicsBodyInReach() const won’t work if
both of GetReachLineEnd() and GetReachLineStart() aren’t const. When they all are const it works fine. It also works if I remove const from all three.

I don’t understand why is that. I have jumble of thoughts.
My thinking is, first function calculation a vector, so I guess it’s changing some value? By why then compiler is allowing it to be const?
Second one doesn’t calculating anything, just getting and returning some location for vector, so it makes sense, why it can (and should) be const.
But I don’t know why GetFirstPhysicsBodyInReach() care about those to to be the same const/non const type as itself.

UGrabber::GetFirstPhysicsBodyInReach() const says that any UGrabber variables aren’t allowed to be changed in the body of that function. When you call GetReachLineEnd() inside the function… c++ doesn’t try and predict whether GetReachLineEnd() is going to do something naughty and still try to modify a UGrabber variable while it is being called inside of GetFirstPhysicsBodyInReach. So you have to put const on that method as well to get permission. You are saying “Yes C++, I am going to be good and not do anything naughty when I call this other function.” If you start with a method that is const, all of the instance methods you call from there have to be const as well.

Privacy & Terms