why avoid recast?

hello, just a random question…
ive watched and read many tutorials, and was wondering, why are they avoiding recast…

" so we dont have to recast…"

If by recast you mean cast to the same thing more than once, than it is because casting is supposedly expensive, so it is better to cast once, and set a variable reference to the object that you are casting to.

A cast is somewhat expensive to do. If you can help it, get your reference casted to a class you know you will need to use often and store it in a variable that is of the same class and not just actor.

i get it now…

when i cast to an actor… then reference to a variable… so when i get from the variable is it the same with casting agian?.. or its less expensive if its stored to a variable?

What a cast does is check if a class is whatever you are casting to is (or a child of) what you think it is. If you need to do something with that actor again later, if you store it in a variable of that class, ue4 will keep that actor as known as that class so you don’t need to check to see what class it is again.

If you only need to use that casted actor for just one instant, you don’t really get much of a benefit. If you need to do something with it later in time, since you already know what type of class it is, you won’t need to do a cast again. It is the benefit of NOT doing subsequent casts is where the benefit comes from.