How to dynamically change Texture variable?

Hi.

I want to change picture of the Texture variable.
I am trying to change it with Texture - Set Source File Path, but it method get many errors:

http://s6.postimg.org/ltfe1wfw1/screenshot_154.png

http://s6.postimg.org/4hf1ggmep/screenshot_155.png

My String variable has value

/Game/GameObjects/Furniture/Tables/Wood_Table/Wood_Table_logo

http://s6.postimg.org/6n9caypv5/screenshot_156.png

How to change this “cursor picture”?

Thank you very much.

A string isn’t just a pointer ot a texture. You have to load it.
But i’m afraid you’ll need to write a custom BP node for that (but it’s easy, don’t worry, it will be about 5 code lines).

Can you provide an example?

Solved with custom BP:

.h file:

UFUNCTION(BlueprintCallable, meta = (FriendlyName = "MyLoadTextureFromPath", Keywords = "my load texture from path"), Category = Game)
static  UTexture2D* MyLoadTextureFromPath(const FString& Path);

.cpp file:

UTexture2D* AMyNativePlayerController::MyLoadTextureFromPath(const FString& Path)
{
	if (Path.IsEmpty()) return NULL;

	/*FString PathToLoad = "/Game/Textures/YourStructureHere";
	UTexture2D* tmpTexture = LoadTextureFromPath(PathToLoad);*/

	return Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), NULL, *(Path)));
}

Result:

This is exactly what I need but I don’t know how to import this code in my project. Would I need to create a new project or there is a way to add this c++ code directly to my project? If you have some time Arthur (or someone else), can you contact me here or on skype => consomer.yourself2 . Thanks for sharing the code by the way and have a good day!

Gabriel.

What about this Awesome Tutorial series? :wink:

Only the name of the tutorial look awesome, thanks!

If I say nothing wrong, I need to choose the «Blueprint Function library»for this?
I need to use this function in widget blueprint.

I have a problem, I’m not really good at c++. What I need to put where is AMyNativePlayerController?

I also change friendlyName to DisplayName, unreal tell me to do this (I trust unreal more than me for this hehe)

There a little screenshot of the .cpp , .h and the message Log.

If you see something wrong tell me please.

Hi! I think that Arthur created new C++ Class (with Player Controll Parent i bet) and called it AMyNativePlayerController. Then he added this code into it’s .h and .cpp. Then he pressed compile. Then he created Blueprintclass based on AMyNativePlayerController. And works with it as if it was just Player Controller Blueprint class but with some usefull modification for u.

Try to put UMyBluePrintFunctionLibrary there :wink:

Thanks for your answer! I try to change «AMyNativePlayerController» for «UMyBluePrintFunctionLibrary» but it didn’t work :(. I also try «MyBluePrintFunctionLibrary», same but without U, didn’t work too. Unreal give me exactly the same error. If you have another idea I’m open to everything!

EDIT: Arthur directly help me, thanks for your answer, we were close to the answer ! It was «UMyBlueprintFunctionLibrary» not «UMyBluePrintFunctionLibrary». All of this for an uppercase :stuck_out_tongue: Thanks again for your help!