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"

create Umaterial using UTexture2D

Hi friends.

I don't know how to import a bmp file on disk from this source and apply it to dynamic material using UTexture2D.

How to create UMaterial using UTexture2D ??

 IsValid = false;
 UTexture2D* LoadedT2D = NULL;

 IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));

 IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(GetJoyImageFormat(ImageFormat));

 //Load From File
 TArray<uint8> RawFileData;
 if (!FFileHelper::LoadFileToArray(RawFileData, *FullFilePath))
     return NULL;

 //Create T2D!
 if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
     const TArray<uint8>* UncompressedBGRA = NULL;
     if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
         LoadedT2D = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);

         if (!LoadedT2D)
             return NULL;

         Width = ImageWrapper->GetWidth();
         Height = ImageWrapper->GetHeight();

         void* TextureData = LoadedT2D->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
         FMemory::Memcpy(TextureData, UncompressedBGRA->GetData(), UncompressedBGRA->Num());


 // Success!
 IsValid = true;
 return LoadedT2D;

Product Version: UE 4.18
more ▼

asked Jun 22 '18 at 12:32 AM in C++ Programming

avatar image


avatar image Spiris Jun 22 '18 at 10:44 PM

Materials generally wrap textures and extend their functionality to meshes and other use cases for rendering purposes. You probably want to create a material in editor that takes a texture parameter as and then in a dynamic instance of that material set its texture parameter to the texture you desire.
This should be super useful:

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

0 answers: sort voted first
Be the first one to answer this question
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