Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question I have issues with terrain rendering.

Discussion in 'Addressables' started by VentaGames, Feb 10, 2023.

  1. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    123
    Ok, i've started with addressable. All works fine, I managed to create groups, etc...
    All works, except terrain. It just not rendering. I've tried to create custom material, moved to different groups, etc... Now, I ended up creating a prefab for my terrain - no luck.
    All other level assets are loaded, even terrain grass and trees are there, but the ground layers - no.
    Also, I've added all my layers to the same assets group.
    I'm using Unity 2022.2.5, any suggestions on where to look?

    Thanks in advance.
     
  2. AlwaysBaroque

    AlwaysBaroque

    Joined:
    Dec 20, 2014
    Posts:
    33
    @VentaGames

    Had this issue with terrains using micro splat terrain shader, although terrain collider was still functioning. Work around was to re-attach shader when instantiating the terrain, use the onLoadDone callback for this.
    I later moved to loading / instantiating scenes with included terrains using addressables no such problem.
    Hope that helps, Good Luck.
     
  3. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    123
    Hi,
    I've tried to change the terrain material while in play mode and it works.
    However, I tried to do the same in code, using terrain.materialTemplate in Start() function - didn't work.
    My terrain is added to the scene. My scene is marked as addressable, so, I'm loading the scene using Addressables.
    LoadSceneAsync. Not sure why this happens with terrain shader. All other objects are visible.
     
  4. AlwaysBaroque

    AlwaysBaroque

    Joined:
    Dec 20, 2014
    Posts:
    33


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.AddressableAssets;
    3. using UnityEngine.ResourceManagement.AsyncOperations;
    4. using UnityEngine.ResourceManagement.ResourceProviders;
    5. using System;
    6.  
    7.     [Serializable]
    8.     public class WhatEver
    9.     {
    10.         public bool _isInstantiated = false;
    11.         public SceneInstance _sceneInstanceObject;
    12.         public AssetReference _assetRef;
    13.  
    14.         public AsyncOperationHandle<SceneInstance> _sceneInstanceHandle;
    15.  
    16.         //private OpenWorldManager _openWorldManager;
    17.  
    18.         public WhatEver(string assetPath)
    19.         {
    20.             _assetRef = new AssetReference(assetPath);
    21.         }
    22.  
    23.         public void SceneLoad( )
    24.         {
    25.  
    26.             if (!_isInstantiated)
    27.             {
    28.    
    29.                 //Debug.Log(_assetRef.AssetGUID);
    30.  
    31.                  _sceneInstanceHandle = Addressables.LoadSceneAsync(_assetRef, UnityEngine.SceneManagement.LoadSceneMode.Additive);
    32.  
    33.                //Register the OnLoadDoneScene callback
    34.                 _sceneInstanceHandle.Completed += OnLoadDoneScene;
    35.             }
    36.         }
    37.  
    38.         // this is not called by you from your code but by Unity when the scene is loaded
    39.         // and only Unity knows when this will be.
    40.  
    41.         private void OnLoadDoneScene(AsyncOperationHandle<SceneInstance> obj)
    42.         {
    43.             _sceneInstanceObject = obj.Result;
    44.             _isInstantiated = true;
    45.             //.................one good use for this callback..................
    46.             //.....................floating origin setup.......................
    47.             //if (_openWorldManager._useFloatingOrigin)
    48.             //{
    49.             //    GameObject[] gameObjects = _sceneInstanceObject.Scene.GetRootGameObjects();
    50.             //    foreach (GameObject go in gameObjects)
    51.             //    {
    52.             //        go.transform.position -= _openWorldManager._floatingOrigin.worldOffset;
    53.             //    }
    54.             //}
    55.             //.................or any other setup you need to perform.........
    56.  
    57.  
    58.  
    59.             //.....put your code to re-attach terrain material/shader here.....
    60.             //................................................................
    61.  
    62.  
    63.             //Activate the scene
    64.             //if ( _sceneInstanceHandle.Status == AsyncOperationStatus.Succeeded)
    65.             //  _sceneInstanceHandle.Result.ActivateAsync();
    66.         }
    67.  
    68.         public void SceneUnload()
    69.         {
    70.             if (_isInstantiated)
    71.             {
    72.                 _isInstantiated = false;
    73.                  Addressables.UnloadSceneAsync(_sceneInstanceHandle);
    74.             }
    75.         }
    76.  
    77.     }
    78.  
    79.  
    80.  
     
    Last edited: Feb 28, 2023
  5. AlwaysBaroque

    AlwaysBaroque

    Joined:
    Dec 20, 2014
    Posts:
    33


    Or maybe try this before the above code.
    Unity - Manual: Using Terrain at runtime (unity3d.com)

    When all else fails read the manual.:)
     
  6. masak

    masak

    Joined:
    Aug 14, 2011
    Posts:
    51
    2021.3.19
    Disabling Draw Instanced helps me.
    I think this is a unity bug.