What I’m essentially saying is that the OP is suffering from a very common misconception ( no doubt propagated by bad youtube tutorials ) that casting is needed to communicate between blueprints.
In C++ you take advantage of the multiple inheritance feature. This means that you DO need to cast even if using an interface but you are casting to the interface part of the object so you still get the decoupling benefits.
Ill post a small C++ example using a C++ interface if you want?
I have solved the Health bar widget with blueprints instead of using code
its now using it with the “Thick” function its not ideal for performance but its the only way i was able to solve it.
If you have an “Onchange” function example , that would be even better.
Also the intention of creating this thread was to learn more about Cast
thats why this thread is called “How To Use Cast”. even if in this situation its not the best solution
And especially for the last part (that i pointed out before) and what to exactly type in different
situations other than in the Onhit function.
So taking the AEnemy example it would be an AEnemy box inside of an AActor box.
With the raw UObject pointer you can’t do much except pass on the boxed Enemy pointer to other classes if you want to without “unboxing” (Casting) it.
But if you want to use a Actor function on the Enemy pointer you need to Cast to AActor which would unbox the Actor. If you Cast to AEnemy you also unbox the Enemy Box and now you can call Enemy functions too.
Boxing and Unboxing is something I personally use to illustrate Casting. The technical term for Boxing is Upcasting (Casting to a Parent Class) and Unboxing is Downcasting (Casting to a Child Class).