How do I assign objects from content browser to variable using code?

Suppose I have a variable U2dTextue and a texture in content browser by the name “/Game/Character/TI_Fire_Tex.TI_Fire_Tex”.

How do I assign it to the texture?

Not just U2dTexture like anything in the content browser how do i assign it.

You can access your texture by using ConstructorHelpers::FObjectFinder template.

ConstructorHelpers::FObjectFinder<UTexture2D> TextureFromContentBrowser(TEXT("/Game/Character/TI_Fire_Tex.TI_Fire_Tex"));

You can do this with other types as well which you can see if you search for FObjectFinder inside your solution. PaperAnimatedRenderComponent uses it to set a default material;

static ConstructorHelpers::FObjectFinder<UMaterial> DefaultMaterial(TEXT("/Paper2D/DefaultSpriteMaterial"));
Material = DefaultMaterial.Object;

i try this several times and always crash, someone can test?

Could you post the trace of the crash? They are in the logs contained in the saved folder.

  1. Do you execute that in your constructor?
  2. Is your variable a pointer?

hello fast reply, thanks!
not in the constructor, in the begin play as a static function from UBlueprintFunctionLibrary parent,
yes is a pointer type UTexture

well the exact very line is the problem ConstructorHelpers::FObjectFinder tex(TEXT(“/Game/RecorridoPolo_001”));, when UE reach the line all explote,
i write wrong?

oh my god sorry i am a crap donkey, of course this only work in the editor not runtime sorry Unity3D extigma

oh my god i am a crap donkey, of course this only work in editor not runtime, sorry Unity3D estigma XD