FString to Image? (C++ & Dynamic Materials)

Any way to convert a String to a Bitmap?

The idea is:
1-To get the player name from APlayerState.
2-Convert it to a bitmap
3-Use it as a texture on a dynamic material

PlayerState->GetPlayerName();

I don’t need to save the image to disk…
In fact, if everything can be done in memory is better.

Any way to do this?

Thank you so much!!


NOTE:


Who says bitmap, also says PNG… in fact I want the transparent (or black) background

Edit: updated refactor simplified to only use material without custom player state
MatName.zip (51.1 KB)

Mostly used info from here:

OFC if you want to have a hard reference to an RT you can always swap out


with a hard reference.

And if you need an image snapshot form the RT you can use Rama’s victory plugin

2 Likes

Hi @3dRaven

I just tested it… did it work for you? It didn’t work for me.

First I tested the user interface.

Create the widget in the level blueprint.
Like this:

And display nothing.


Then I did other test, because I want to see the text on the mesh.


Then in the widget I created a function that returns the canvas

And a Event Dispacher is called when render is done.

A new translucent material

Apply it to the sphere

Then create Widget from the sphere (To get the widget instance easily)

And then Create Dynamic MaterialInstance from the sphere material and set texture parameter value…

It doesn’t work either…

Something must be wrong from the beginning.

Any idea?

Thank you so much!!

Its obviously working, but the rt rendering portion isn’t.
Where is the bit that draws the image? (Initial call to the draw function, and the value set for canvas).
And is it using the correct font with the correct settings? Roboto could be empty.

Do you mean this?

It is practically the same as the original… it just adds the delegate and the function.

You can take a look
MatName_MOD.zip (85.5 KB)

Not at rhe pc.
Possible issue is your brush material - and the fact that you have translucent somewhere.

You need to make sure the texture writes first - id add a breakpoint to the end of the functolion and check to see if it actually called + froze the RT in memeory.

Then you also need to make sure the material is properly using the RT - usually they have a filename you need to set yourself when you create them.

There is at least 3 materials involved.
One to write to, one to write with, and the final one to display what you created to whatever region you need.

1 Like

Ok, I’ll try to do what you say.
Thank you very much for the help

This time I used the first test (With the material for “User Innterface” → From original example provided by @3dRaven )

It started working after a few loops through the brackpionts.
I also put some delays in some places.

Then I removed the breakpoints and delays and now it never fails… it always works…
I think there is something loaded in memory that makes it work. (because it is exactly the same as when it didn’t work).


I also tried the other test, this time with an opaque material.

But for some reason that I don’t understand I can’t remove the widget from the viewport .
So I can’t see the Sphere and I don’t know if it’s working…


It only worked because of breaksponts and delays helped… for me it’s not a valid solution, it just helped something to load into memory. But on different computers it will take different times that’s why delays are not reliable.


Works on my end

1 Like

The only thing in memory should be the render target.

Is that being cleared by the script on first run?

Can you try it with the sphere please?.. wait a minute while I zip it and put it here

MatName_MOD2.zip (88.1 KB)

No, as far as I know it doesn’t delete it.

Posted it on an unlisted YT vid, windows capture cut off the last clip.

It gets the pc name by default if none is assigned.

Maybe your pc name is empty and you didn’t assign a name to the player manually?


Added some quick rename code

In game

It’s on the other side

1 Like

It worked for you…
How did you remove the widget from viewport?


This doesn’t work for me…


I’m going to delete the intermediate and saved folders…
Maybe the engine is making jokes

I’ll be back in five minutes.

Remember you can convert variables into validated gets

It’s a little cleaner

You have a create widget node in BP_GameMode…that is probably the orphan widget that stays

Remember to use ctrl + F inside of a blueprint to find all instances used in the project

Gives you the full results

1 Like

Ok… that’s it… I was going crazy LOL

However the text on my sphere is not working.

Did you make any changes to my code?

No I don’t think so, all I did was to hook up the set brush from material node that was disconnected. That was needed otherwise no update would matter.

I’m guessing you may need to shift the position if you want the text in the middle of the sphere.

Added some emissive to the material

I can send you the scene if you want.

Even connecting the “Set Brush from material” node it still doesn’t work for me…

For now it would be a great advance if I could just see it.

Did you change the position of the text?

is this?

ok… wait a minute I’ll try with 500 on the Y like you did

MatName_MOD2 (2).zip (298.6 KB)

Full scene just in case

Oh and I added a test button to the widget just to make sure it’s the same one.
There is an enforced input for player 0 and a remove parent command for tests before I found the game mode widget add

1 Like