Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cannot change basemap texture in webgl build

Discussion in 'Universal Render Pipeline' started by menguzat, Jun 5, 2020.

  1. menguzat

    menguzat

    Joined:
    Aug 20, 2017
    Posts:
    15
    Hi,

    I have a script that fetches a texture image from an url and loads it to the basemap of the material of a gameobject.

    it works perfectly in the editor, but doesn't in the webgl build.

    It fetches (and caches) the image (it says so in the console) but the material's texture doesn't change.

    Code (CSharp):
    1.     _texture = await GetRemoteTexture( url ); //this is a function I found online which basically fetches a texture through UnityWebRequestTexture.GetTexture
    2.  
    3.     _texture.wrapMode=TextureWrapMode.Clamp;
    4.  
    5.     Renderer rend = GetComponent<Renderer>();
    6.     rend.sharedMaterial.SetTexture("_BaseMap",  _texture);
    This is the code I use. The material is an URP/Lit shader. It renders the default texture in WebGL, fetches the image, but doesn't replace it (only in WebGL - it replaces just fine in the editor-game view).

    No errors, no sign that something's wrong. It just doesn't work.

    Any ideas?
     
  2. menguzat

    menguzat

    Joined:
    Aug 20, 2017
    Posts:
    15
    Still struggling with this. I tried to use another shader but it's still the same.

    By the way, something I forgot mentioning is that I'm calling the code above from external javascript on the page like this:


    Code (JavaScript):
    1. function loadit() {
    2.         var url=document.getElementById('url').value;
    3.         unityInstance.SendMessage('Cube','LoadTheTexture',url);
    4.       }
    I know that it actually works because it fetches the texture (the console logs "[CachedXMLHttpRequest] 'http://xxxxxxx/DSF0374-copy-scaled.jpg' downloaded successfully (743969 bytes) and stored in indexedDB cache").

    But nevertheless, the SetTexture part only works in the editor, not in WebGL.