First of all, the “CastToActor” is not needed. HitActor is already of type actor. Since you are using Interfaces, you don’t need to cast.
Actors that don’t have this Interface won’t do stuff when calling it on them, since there is no implementation for it on them.
I will write it down again:
- When you hit something, so the ReturnValue is TRUE, you check if the “OutlineHit” Reference is Valid.
Means, you check if you already saved something in it or if the Variable is empty.
In other words, you check if you just traced something with the trace that happened before or if not.
1.1. IF the “OutlineHit” Reference is Valid, it means you JUST traced an Actor before, that you probably saved into this variable, and you need to check if you are now
tracing the same actor again or a new one. So you compare the variable with the HitActor.
1.1.1. If they are EQUAL (Branch is true), you’re tracing the same actor again, so nothing to do.
1.1.2. If they are NOT EQUAL, you’re tracing a NEW actor, so you remove the outline from the one that is saved in the variable,
add the outline to the new one (HitActor) and save HitActor into the “OutlineHit” Reference.
1.2. IF the “OutlineHit” Reference is NOT Valid, it means you traced nothing before, so you don’t need to think about the Variable and just deal with adding the Outline to the HitActor.
After that, you can save this HitActor to the “OutlineHit” Reference.
- When you are not hitting stuff. You check if the “OutlineHit” Reference is Valid.
2.1 If YES, you remove the outline from the “OutlineHit” Reference and set the Reference to nothing.
2.2 If NOT, you don’t do stuff.
Hopefully that is better explained.
It also might help you to watch this Stream to get better knowledge of casting, reference, interfaces etc.