I am having trouble casting my hit actor from a single line trace to my custom blueprint class (which inherits from Character). I broke the hit result struct, then next cast the hit actor to my custom class (so that I can retrieve a variable from it), but the cast fails every time. I know that the hit result is the correct object because when I print its name, it is correct. Any idea as to why this is the case? Basically, I just need to cast the hit result actor to my custom class, which inherits from the Character class. Thanks in advance.
Thanks for trying to help. I managed to figure this one out by messing around with it. It turns out that it was just a simple problem with my line trace when my character looked up from the baseline, towards where I had just moved the object of interest. The line trace was hitting my character’s own capsule when looking up, as the start point originated from the player’s “eyes”. I just made the line trace ignore the player character. I thought it was still hitting the correct object but I had taken off the print node because I thought I wouldn’t need it anymore. Now I know to only change one thing at a time. Anyway, it is all good now. Thanks for trying to help.
I just wanted to mention for other people who might end up here with a similar issue:
When you break the hit result from a trace and you get the Hit Actor, this is an object reference meaning that the trace is returning a specific object from the world, not a class reference. So if you are trying to avoid casting to the BP type to save on processing and instead compare it to a BP type like I was trying to do by using Hit Actor == and then specifying the blueprint type, it will always fail because the actor in the world that you’re hitting is NOT a generic reference to the original BP, even though they are the same type of blueprint. Instead, you need to get the class of the Hit Actor and then compare that == to the original BP class. It took me a minute to realize why the check was failing.