I’ve been looking at the documentation for a very long time and I can’t figure it out. I haven’t been able to find a website, video, or person that can explain how to read Unreal’s documentation.
Can someone explain how I can use the Cast template in this way I described in the title?
If your object can’t be casted to the specified class because it doesn’t inherit from that class, Cast<>() will return a nullptr. The if(…) is preventing NullPtrExceptions when calling the member function / method.
What does YourObject need to be? I’m trying to use a function that is declared and defined in an actor component inside of a different actor component.
I’m still confused about these three lines. I’m using an “Interact” actor component on my PlayerCharacter to, when f is pressed, ray cast for an actor, check if that actor has one of the three interaction components (Quest, Shop, or Ambience), then return the interaction type. Then, inside Interact.cpp, it executes the corresponding function.
Well, if the function has the same signature in all the interaction components (for example bool Interact()), than it would be best to use an Interface. Because only then you can perform a cast based on the interface class for all three cases instead of casting to a class:
Unless all three component classes have the same parent where the interaction function is declared though. But it’s really hard for me to explain this here if I don’t know exactly how your code looks like.