Well I managed to pull it off and got it, but it’s really strange.
Can anyone help me on this please.
What I did is I set a material on an object, on a cube mesh.
I set UPROPERTY withEditAnywhere option for my texture that I uploaded, this is a way to sort of see if I uploaded anything, because the uproperty edit anywhere has an icon inside the editor, it will create a section for the variable and it is the texture it loaded from the disk in fact, so I was happy to see it as an icon there inside the editor.
The problem is when I try to attach with C++ the texture to the material it crashed my editor.
But if I try to add any other texture with C++ to the material that is set on the mesh then it does not crash.
Why is this texture causing a crash.
I set the texture on the material like this.
DynamicMaterialInst->SetTextureParameterValue(FName(“DynamicTexture”), TextureD);
Component1->SetMaterial(0, DynamicMaterialInst);
I get a crash.
But I have another texture for tests, TextureB.
The only thing about this textureB compared to TextureD is that I imported it to the editor with the editor import buton, it’s imported from the editor, so I used the editor to load a file from disk, and this file texture works and the other does not
I use it like this.
static >ConstructorHelpers::FObjectFinder<UTexture2D>TextureFinder(TEXT("Texture2D'/Game/container.container'"));
Then
TextureB = TextureFinder.Object;
Later in the start play function I set the material on the static mesh.
DynamicMaterialInst->SetTextureParameterValue(FName(“DynamicTexture”), TextureB);
Component1->SetMaterial(0, DynamicMaterialInst);
So it works with this texture but not with that ?
How come , what is the difference between the uploaded texture from the editor with import button near add components, and this one imported from C++
Really this wrapper is full of bugs, or I’m not doing things the way they should be done.
But I think it’s just more of a bug since my texture appears in the editor as a variable(editanywhere) with an icon, so it loads the image, converts it into 2DTexture, but refuse to attach to material and to component mesh
The two textures declared inside the header file.
UPROPERTY(EditAnywhere)
UTexture2D* TextureB;UPROPERTY(EditAnywhere)
UTexture2D* TextureD;
I also have this in my constructor.
DynamicMaterialInst = UMaterialInstanceDynamic::Create(StoredMaterial, Mesh);
In the begin play I have the convertor to convert the image to a 2DTexture once it exits the raw array.
> Width = ImageWrapper->GetWidth();
> Height = ImageWrapper->GetHeight();
> TextureD = UTexture2D::CreateTransient(Width, Height, PF_B8G8R8A8);
> void* MipData = TextureD->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
> FMemory::Memcpy(MipData, RawData->GetData(), RawData->Num());
> TextureD->PlatformData->Mips[0].BulkData.Unlock();
> TextureD->UpdateResource();
and later in the begin play I set the texture.
DynamicMaterialInst->SetTextureParameterValue(FName(“DynamicTexture”), TextureD);
Component1->SetMaterial(0, DynamicMaterialInst);
This causes a crash with TextureD,
If I use texture B then it works and no more crash I see all textures loaded textureB textureD when I hit play, break it with console key and look in the Detail tab of the components.,
I use the constructor helper to find TextureB in the editor folder location, and just set it down here in the begin play.
Change it to TextureB
DynamicMaterialInst->SetTextureParameterValue(FName(“DynamicTexture”), TextureB);
Component1->SetMaterial(0, DynamicMaterialInst);
I can see TextureD because tho I don’t set it on the material (to cause a crash) The texture is loaded from the disk with C++ but not attached to the material that is attached to the mesh.
All textures are visible except that TextureB is set on the material not TextureD, I Set it with textureD I get a crash. It taken me already a week, it’s so frustrating
Can someone at least tell me the difrence between the two textures.