In Blueprints when I create some new object (class) I can select mesh, material etc with the comfort, that if I change in anytime localization of my asset, blueprint will update by itself. Sadly, I don’t have similar option in C++ - here I always use ConstructorHelpers::FObjectFinder
to grab asset I need. Please tell me if there is any other method to look for asset - assuming, for example, that its name is unique, localization can change etc etc. Maybe I should not use ConstructorHelpers - so far I didn’t check source code of blueprint creation.
Asset localisation fix-up happens in the bowels of the package loading code, so it doesn’t really matter how the asset is loaded (basically, if anything asks for /Game/MyAsset and we find that there’s a /Game/L10N/{CurrentCulture}/MyAsset, we’ll load the localised version and pretend that it’s /Game/MyAsset).
One downside to finding assets in code (and you can use FindObject
/LoadObject
as well as the ConstructorHelpers
) is that the cooker won’t know about those references, and so won’t cook your assets unless they’re also referenced in the editor somehow (there’s some project packaging settings that let you specify “additional assets to cook”, which exist as a way to workaround this).
Another downside to code-references is that they’re fragile against assets being moved/renamed, as fixing up redirectors in the editor can’t update code references (but can update asset references, such as those in a data table or data asset).
For that reason it’s still best to find assets via a reference the cooker and editor will know about, even if that means creating a data table or data asset to host the references (and you can use string asset references if you want lazy loading behaviour), and then using that data table/data asset at runtime to get your hands on the reference.
Yeah, so how exactly I should reference objects in a code?
Without more information about what you’re trying to do, I can only refer you to my previous answer about the general downsides of in-code asset references, and the ways you can mitigate them.