Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to let player draw on widget and save image?

Hi all,

I would like to build a system where a player can draw lines on the screen using their mouse, and then save the drawing they have created to be loaded at another time. What would be the best way of achieving this in UE4 using blueprints?

If there is a way to achieve this through C++ then please mention it as well, but i'd ideally like this to be blueprint based as my experience in C++ with UE4 is limited.

Any suggestions?

Product Version: UE older version
more ▼

asked Jan 10 '17 at 03:32 PM in Blueprint Scripting

avatar image

Chris Gray
3 2 5 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You want to be using render targets for this. You should watch Epic's training stream to get a basic idea of how to set up blueprint render targets https://www.youtube.com/watch?v=1Z-V1Buk6z8

As for saving / loading the render targets, that's a little bit more complicated. There isn't any out of the box functionality that I'm aware of to do this, so I've had to piece together my own solution in C++. The basic idea is that you want to read the pixels from the render target and write them to disk. You can then initialize a new render target with this saved data at a later time.


Skip to the bottom and look at the AHeightMapReader::UpdateBuffer() method in his code. Also take note of the "non blocking update buffer" method used beneath this. Reading pixels from a render target is a fairly expensive operation, and I personally found this solution to be quite necessary!

In my own implementation I am writing the pixels to my saved game object. To load my render target I then grab the pixels in my saved game object and initialize a new Texture Object from these pixels (see FImageUtils::CreateTexture2D()) One thing to be aware of when using this method is that it does contain editor only code, so you'll probably want to have a look at Rama's alternative version of this function which you can find here. https://answers.unrealengine.com/questions/33571/fimageutilscreatetexture2d-causes-brief-hang-is-th.html

Once you have a Texture2D that you've created from the saved render target data the rest is easy! You can just draw it to a fresh render target!

something like this:

 UKismetRenderingLibrary::BeginDrawCanvasToRenderTarget(this, NewRT, RTCanvas, DrawSize, RTDrawContext);

 RTCanvas->K2_DrawTexture(SavedRTTexture, FVector2D::ZeroVector, FVector2D(RTSize, RTSize), FVector2D::ZeroVector, FVector2D::UnitVector, FLinearColor(1.f, 1.f, 1.f, 1.f), EBlendMode::BLEND_Translucent);

 UKismetRenderingLibrary::EndDrawCanvasToRenderTarget(this, RTDrawContext);

I hope all of that made some sense. Apologies if not, I'm still figuring it all out myself :) It would surely be nice if Epic provided some better tools for handling render targets inside blueprint!

more ▼

answered Jan 13 '17 at 05:21 PM

avatar image

74 4 11 13

avatar image UnexpectedSquirt Jan 13 '17 at 05:34 PM

Oh! And I'm not totally sure what your goals are , but if you aren't using a save game object you can also use the blueprint function "ExportRenderTarget" to just write the render target to disk as an HDR image. This would work fine if you're cool with having a bunch of loose image files on the disk :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question