0

Simple question but perhaps Unreal Engine specific: I have UMyBaseClass and UMyDerivedClass, have defined a function as taking in UMyBaseClass as a parameter but, when trying to pass in UMyDerivedClass, I get the build error: "cannot convert argument 1 from 'UMyDerivedClass *' to 'UMyBaseClass *'". I've been passing in a bunch of unreal's derived Aclasses without issue so far so I'm thinking there may some extra leg work involved in UMyBaseClass or simply that UObject derived classes are funky. Any inspiration?

NB. Functions are being overridden from a custom Interface class.

Sean_M
  • 1
  • 1
  • 1
    Probably you’re not including the file containing UMyDerivedClass in the file where you’re passing it. The compiler needs a full definition to make sure types are actually related. – George Jun 02 '22 at 09:17
  • I wasn't, you're right. But also, it's also completely fine to upcast to the base class. I've been scared of casting as I heard it forces runtime checks but (and this is for the benefit of anyone harbouring similar concerns) that's only true of downcasting. Thanks for your reply! – Sean_M Jun 03 '22 at 10:35

0 Answers0