x

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 can I use a dynamic 2D texture with a plugin?

Currently a UTexture2DDynamic can't be used in a plugin because it has no methods exposed with the ENGINE_API so trying to initialize it with Init() causing link errors.

I could use FSlateTexture2DRHIRef for a dynamic texture but I don't think I can plug that into a MID as a texture parameter.

What is the right way to create a dynamic texture, lock and write to it every frame, and plug it into a MID. Is UTexture2D::CreateTransient() a dynamic texture?

Product Version: Not Selected
Tags:
more ▼

asked May 10 '14 at 05:48 PM in C++ Programming

avatar image

zoid
326 11 14 226

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

2 answers: sort voted first

I created a wikipage containing multiple solutions to this problem, the most performant one is first and lets you update subregions of the texture using ENQUEUE_UNIQUE_RENDER_COMMAND

https://wiki.unrealengine.com/Dynamic_Textures

more ▼

answered May 12 '14 at 03:08 PM

avatar image

zoid
326 11 14 226

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

I just use a FTexture2DRHIRef and create it using RHICreateTexture2D passing it TexCreate_Dynamic if you need to update it every frame

more ▼

answered May 12 '14 at 12:45 AM

avatar image

Ehamloptiran
1.5k 50 9 59

avatar image zoid May 12 '14 at 05:40 AM

Hi there, this doesn't address the real issue which is that an FTexture2DHIRef can't be passed to a UMaterialInstanceDynamic to replace a texture input.

avatar image Ehamloptiran May 12 '14 at 06:10 AM

Sorry, create texture using CreateTransient in UTexture2D. Then to lock and write to it use

 FTexture2DMipMap& Mip = [Texture]->PlatformData->Mips[Level];
 void* Data = Mip.BulkData.Lock( LOCK_READ_WRITE );
 FMemory::Memcpy( Data, NewData, DataSize );
 Mip.BulkData.Unlock( );

Then pass the UTexture2D to your MID to show.

avatar image zoid May 12 '14 at 02:50 PM

OK for this method to work you also have to call UpdateResource() on the texture. This destroys the underlying HRI texture resource and recreates it from scratch. This is very costly in terms of performance, definitely not suitable for the application in my original question which is doing this every frame.

avatar image Ehamloptiran May 12 '14 at 02:53 PM

I would recommend that you post your solution regardless. Both cases will have their uses

Edit: you posted too quickly for me. You'll need to look into a method that maps the underlying resource then.

(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