Cast to BP generated class

Hi,

I have an some UI elements done in BP that inherit from UMG User Widget. I want to access those widgets inside my C++ code but I’m not sure how I can cast an object to a blueprint class. The other solution that I was thinking about was to just write my widget class in C++ code but I wanted to know if there’s a way I can cast a UUserWidget to MyBPCreatedWidget inside C++.

The MyBPCreatedWidget does not have an associated type in C++, so there is no way you can use it directly. The standard approach, if you need C++ access to properties/ufunctions, is to declare them in a C++ class and use that as the blueprint’s parent. Note that you can still leave the property defaults/function implementations to BP if you want.

The only other option is to get a UClass pointer at runtime and then iterate over the fields, but this is long winded and not intended for this kind of scenario.