Troubles with rawImage (trying to show some Texture2D)

Hi

I’m using rawImages to show some texture2D in my UI.

The purpose is to browse some textures on the computer and apply it to my mesh. meanwhile i’m drawing the Texture2D on a rawImage to visualize it.

My new texture apply correctly on my mesh, but doesn’t show on my rawImage.

If I make a texture2D with a .png image per example, this texture2D will apply correctly on the mesh, and it will applay correctly on the rawImage.

If I make a textur2D with a .tga file, it will still works on the mesh, but my rawImage will be set transparent :frowning:

see:

On the left I have a list of all the materials used on the mesh. I can select a new image on the computer to replace the current texture:

Here I will replace the texture for the “hull” material. I will select a png texture :


It works perfectly.
Now same thing with a .tga texture :


As you can see it works fine on the model but the rawImage did not liked it. Here is my code :

public Texture2D LoadTextureFromPath(string path)
    {
        Debug.Log("Loading " + path);

        if (path != null)
        {
            Texture2D newTexture = new Texture2D(2,2);

            if (path.Contains(".tga"))
            {
                Debug.Log("this is a tga texture");
                newTexture = TGALoader.LoadTGA(path);
            }
            else
            {
                Debug.Log("this is not a tga texture");
                byte[] byteArray = File.ReadAllBytes(path);
                newTexture.LoadImage(byteArray, false);
            }

            newTexture.Apply();

            return (newTexture);
        }
        else
        {
            Debug.Log("Failed to load image at path: " + path);
            return null;
        }
    }
// Invoked when clicking on item button
    public void setTexture()
    {
        string path = ViewerManager.instance.selectTexturePath();

        Texture2D newTexture = ViewerManager.instance.LoadTextureFromPath(path);

        //apply new texture on the model material (this works -> model change appearance in game view)
        ViewerManager.instance.materialsDict[materialName.text].SetTexture("_MainTex", newTexture);

        m_material = ViewerManager.instance.materialsDict[materialName.text];

        m_RawImage.texture = newTexture; // this doesn't works : rawImage become transparent
    }

Any ideas on this ? Or alternative ways to proceed ?

Any help appreciated, thanks

Fixed !
This comes from the TGA loader
answer is here :

7450859--914030--upload_2021-8-26_10-30-14.png

1 Like

It doesn’t matter now, but I was just writing to you. You are posted in the wrong forum, you want to post this in UGUI & TextureMesh Pro forum. RawImage is part of the original UGUI, not the UI Toolkit which is new. Probably get better answers there for any future issues like this.

1 Like

I will move the thread.