RealTime Material Creation

I wasn’t sure which section of the forum to put this in, but my current method falls mostly into this category I think.

In the program I’m making I’m trying to dynamically create a image file based on input from the user. So basically if they were to hit an arrow key it would draw a line in the direction of that arrow. I would then display a picture of their drawing back to them in the program. The method I’m trying to use right now is modifying a tutorial I found on Render Targets to accomplish this. I get the approximate middle of the render target and draw set sized lines based on the user input. This is being done through calls to draw material to the canvas on the render target. I just chose a starter content render material for what is being drawn. That all is working fine and shows up in game. I then export that as a file to disk (ExportRenderTarget) and re-import it as a Texture2D (Import File as Texture 2D). I display the picture, but anything drawn is not there. It’s just the set backcolor of the render target. I’m very new to this, so I’m guessing that I’m lacking some understanding when it comes to the difference between the texture and the material. I’m guessing that I’m just exporting the texture whereas what’s being drawn is stored in the material? When I open the .png file that is created on my computer the drawing is there, but not in the color shown in the game.

Thanks for any guidance.

Just for some more clarification as I’m working on this more. If I import the file into the editor and I go into the texture viewer I see the drawing there. However if alpha channel is check its showing up as transparent. If I uncheck alpha it shows up as black. Now I’m a bit worried that it actually is there, but is just transparent so I can’t see it…

It may require using a node in the material render target that enables the texture’s alpha channel when the drawing is being drawn, or at least somewhere during when it’s exported and re-imported. But it really sounds more complicated than that, or it’s something else causing the issue. What is the workflow for exporting the drawn .png? PNG is not an entirely lossless format, so it could be occurring with how Unreal handles that file type by default. What exactly is the final goal of this functionality in the game?

I took some screenshots and tried to upload them, but it keeps telling me it’s missing information, so I will try to figure out how to add them later.

Here is the basic workflow of the project:

Create RenderTarget 2D → Set as Variable “My Render Target” → Clear Render Target 2D

Create Dynamic Material Instance → Set Texture Parameter Value (Value is my render target and the target is my dynamic material instance) → Set Material to a square mesh I have to see it

Create Dynamic Instance → Set as Variable (Material used in draw material)

Begin Draw Canvas to Render Target → Draw Material → End Draw Material

Export I’m doing from C++ through Export Render Target – I mainly try to work in C++, but have been trying to get comfortable mixing in blueprint especially seems nice for stuff like this.

Import - Import File as Texture 2D with the filename being the Project Content Directory

The idea is to take user input over a period of time and be able to draw a map of it back to the user to show the path they took. Something similar to a minimap with fog of war. It starts out all black and based on user input (walking around) the material is changed dynamically to show path. However I’m new to this so I’m thinking small steps. So i’m saving user input over a period of time and just trying to get that to modify a image. I’ve got the input part down I think I’m just not sure what’s going on with the textures.

Thanks for the help. Sorry for the lack of pictures I’ll try again later to get them to upload. I’ll look in the forum for upload directions. I think I’m just missing a step.

Well I got it working… Unfortunately, I’m not 100% sure what I did to fix it. I messed around with the materials being used. I’m pretty sure the material I was using to draw on the canvas was drawing in the alpha channel and was therefore transparent. I played with that a bunch and it now shows up lol. I wish I could say I have a solid understanding but I understand a bit more than yesterday.

As a separate but related question writing this thing to disk only to re-import it seems pointless. Is there a way to just get the texture from the render target while keeping it all in memory and avoid the disk write?

Edit: Found that the render target itself is a texture so I can use that as my image directly. Great!