205. AimOffsets

I was listening to a lecture, and at this part, they said, ‘The current event graph is overwriting everything with zero, so nothing can be adjusted in the animation preview.’ This is what they said, but I don’t understand what it means.

The above graph is an animation blueprint.

This would be because “TryGetPawnOwner” will return a object reference of “none”, which is another way of saying that the object reference is empty (it cannot find the Pawn Owner). This is expected behaviour in an animation preview, but as a result the other nodes will not return the values you would expect and set things to zero.

This is where that “Is Valid” node will come in handy, cause you can use it with a branch to stop this from happening.

Do you mean that if you don’t have Pawn Owner, you set everything to zero?

That is correct! To break down why:

If TryGetPawnOwner does not return an object reference to the owning pawn, then we cannot get it’s velocity, which is returned as a zero vector (a vector with XYZ coordinates of (0, 0, 0)), then vector length return a value of 0. So Speed is set to 0.

Likewise, since there is no object reference to the owning pawn. GetActorTransform returns a transform with its values set to 0, and since the transform is zero and the result from GetVelocity is a zero vector InverseTransformDirection also returns a zero vector. Then RotationFromXVector also returns 0 because it’s being supplied a zero vector, which then sets Angle to 0.

Aha I understand now. Thank you. So the reason I used Is Valid is to prepare for when there are no objects, right?

I have one more question.


I added the above picture to the sequence. But I wonder why you just cast as a character, not a shooter character. Can’t I do it with a shooter character?

You 100% could, and you’d get access to the same access to those nodes. There’s an understanding when programming that you should give/take only the access that you need to do the task, as that helps keep your code clean while also making sure tasks are done as efficiently as possible.

Now, I doubt that there would be a noticeable performance hit if you decided to cast to ShooterCharacter. But if you don’t need access to the functions/variables of ShooterCharacter then we try to gain access to it?

I apologize, but I didn’t quite understand this part. Could you please explain it to me again?

It was a bit of an open question. But to reword into a clearer statement. If you don’t need access to the functions or variables contained specifically in ShooterCharacter, then there is no need to potentially use more performance by casting to ShooterCharacter and just cast to Character instead.

That said, I do not know what the exact performance difference would be. If there even is one.

Now I understand. Thank you very much for explaining it to me.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms