Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

[FREE]MicroSplat, a modular terrain shading system for Unity Terrains

Discussion in 'Assets and Asset Store' started by jbooth, Aug 9, 2017.

  1. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    85
    I know but how should it look to be setup correct? How do I know if my is setup correct?
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Can you post a screenshot of your terrain component?
     
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    So I was looking into a similar issue today and remembered that your using the latest github. In that version, I changed snow and other systems to share samplers with the control0 splat map texture. This works fine for Unity Terrains, because it sets the texture to Wrap, but the mesh workflow used to set those textures to clamp- so if you happen to be using external splat maps, set them to wrap.
     
  4. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,033
    Ah, thanks, I'll try that -- but will that fix problem #1 too?

    Also, regarding 2018.3 -- the MS material inspector is messed up (just a list of textures and settings, like if I use too many samplers on Mac), and errors in the console. What should I do? (This is on Windows, with MS pulled from github yesterday, and there is no Debug panel.)

    Could not create a custom UI for the shader 'MicroSplat/AmethystTerrain_x6_y1'. The shader has the following: 'CustomEditor = MicroSplatShaderGUI'. Does the custom editor specified include its namespace? And does the class either derive from ShaderGUI or MaterialEditor?
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  5. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,033
    For the snow issue: I'll change the mesh terrain control maps to Repeat, but I was seeing the problem on Unity terrains as well (streaking on UV scales larger than 1). And what would I do on Blendable Objects for the problem with them?

    thx
    Dave
     
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Hmm, that's odd- maybe it needs a JBooth.MicroSplat in front of it? Can you try adding that and see if it fixes it? I wonder if I'm being to aggressive trying to share that sampler- always nice to have more samplers available. I haven't looked at the snow/blend issue, but it might cause an issue there as well.
     
    Last edited: Dec 14, 2018
  7. threeguysgamestudio

    threeguysgamestudio

    Joined:
    Dec 1, 2017
    Posts:
    23
    Same problem concerning 2018.3 & NullReference in RestorePrototypes() at line 245,

    screenshot of my MicroSplat component attached.
     

    Attached Files:

  8. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Ok, pull now, should be all fixed up.
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Does everything work fine when this happens? Wondering if this is a one off error that happens when upgrading, or something that can be repro'd?
     
  10. threeguysgamestudio

    threeguysgamestudio

    Joined:
    Dec 1, 2017
    Posts:
    23
    It's perpetual - whenever the scene loads the texture appears 'default' pink, have to 'sync' the MicroSplat component for the textures to appear. Then, when hitting play, the refs are lost again and a whole mutiny of errors occur, and the MicroSplat component is disabled automatically.

    If I enable it the textures appear as normal, however, I cannot build due to the errors.
     
  11. threeguysgamestudio

    threeguysgamestudio

    Joined:
    Dec 1, 2017
    Posts:
    23
    Two images attached: First shows a 'fresh load' of the scene. Second shows what happens after I enable the Micro Splat Terrain component, which as been automatically disabled. The same thing occurs each time I hit 'Play'. microsplat2.jpg microsplat3.jpg

    The same error occurs each time I click 'Sync'
     
  12. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Do you have the files locked via revision control system and they aren't being updated correctly? Do you have other components on messing with the terrain system? (I thought someone had a bug with something like this last week and it ended up being some component they had setting stuff in the TerrainData object)

    I've been playing/building on OSX and Windows all day and haven't hit this error. Does this happen in the example scenes on a fresh project, or only in your game?
     
  13. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Version 2.2 submitted. Changes:

    - Ability to triplanar more stuff; mainly texture cluster noise and normal noise
    - Better sharing of samplers. If you've ever hit the dreaded 16 sampler limit, then this update removes the following unique samplers: Snow Diffuse, Snow Normal, Texture Cluster Noise, Noise Normal 1, Distance Noise, Detail Noise, Streams/Lava Texture.
    - New options for the Distance Resampling functions; A constant mode, where no cross fade is performed and the resampling in continuously blended with the regular texturing, and a noise mode, which uses a procedural noise function to blend between the regular and resampled textures.
    - Fixed some compile issues in 2018.3 with KeyDown event

    This is a sync'd update, so it means a PITA update of all modules ;)
     
    mons00n likes this.
  14. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,033
    Thanks! And more shared samplers! :D
     
  15. threeguysgamestudio

    threeguysgamestudio

    Joined:
    Dec 1, 2017
    Posts:
    23
    There's nothing on the terrain object except:

    Transform
    Terrain
    TerrainCollider
    MicroSplatTerrain

    Not using a revision control system.

    -----------------------------------------

    I think the TerrainData may have somehow been corrupt before the Upgrade and the new code is exposing it. The TerrainLayers array is the correct size (4 in my case), however, they're all null (see image).

    When I use the 'replace layer' feature to add them back in, the errors go away when I 'sync', however, upon hitting Play or reloading, the TerrainLayers are 'null' again as shown in the image. Seems like the updates I'm making to the layers aren't saving properly to the TerrainData file...

    *Edit (I'm replacing the layers using the layers found in the new _TerrainAutoUpgrade folder which I'm assuming Unity added to my project upon upgrading to 2018.3)

    *Edit2 (The TerrainLayers immediately revert to Null upon saving the scene after using the "Replace Layer" option.
     

    Attached Files:

    Last edited: Dec 15, 2018
  16. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    I just tried 2018.3.0f2 and I still get this when I hit 'update' on the texture packer?

    Code (CSharp):
    1. Graphics.CopyTexture called with mismatching sizes (src 2048x2048 dst 1024x1024)
    2. JBooth.MicroSplat.TextureArrayConfigEditor:CompileConfig(TextureArrayConfig, List`1, String, Boolean) (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:1408)
    3. JBooth.MicroSplat.TextureArrayConfigEditor:CompileConfig(TextureArrayConfig) (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:1557)
    4. JBooth.MicroSplat.TextureArrayConfigEditor:DelayedCompileConfig() (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:871)
    5. UnityEditor.EditorApplication:Internal_CallDelayFunctions()
    When I look at the generated assets, it looks like most of them succeed: it's only the normSAO assets that are not updated.
     
  17. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711

    This does not look like the copy texture bug, but perhaps a bug in the system that scales the textures to all be the arrays target size. Any chance you can send me the data to look at?
     
  18. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    203
    Hi, running well on 2018.3.0f1, but wondering if you have some tips to tap into terrain performance gains.

    I'm procedurally generating terrain with mapmagic.

    Any tips for this setup? Typically have 6-9 terrains live at a time, all using the same microsplat layers and using the mapmagic-microsplat sync script
     
  19. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Most likely your CPU bound, but if you were GPU bound then looking at the sample count in the bottom of the material will give you a pretty good idea of how expensive each feature is as you turn them on and off.
     
  20. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    I took a closer look at my setup for the texture packer, and I noticed my size for the smoothness was unintentionally not set to the same size as my other textures (see image). I changed it to match the others, and it fixed the error. Which makes sense since the error given appears to be a size mismatch. I changed it back to 1024 and the error came back. Pretty easy to replicate. copy-texture-bug.jpg
     
  21. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    Got another hiccup with the texture packer. Using AntiTileArray, if I have nothing in the Detail and Distance slots for all my textures (but do have a normal texture -- see image). I get this failed assert:


    Code (CSharp):
    1. Assertion failed on expression: 's_AssetProgressBar.dialog'
    2. UnityEditor.AssetDatabase:SaveAssets()
    3. JBooth.MicroSplat.TextureArrayConfigEditor:CompileConfig(TextureArrayConfig, List`1, String, Boolean) (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:1523)
    4. JBooth.MicroSplat.TextureArrayConfigEditor:CompileConfig(TextureArrayConfig) (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:1545)
    5. JBooth.MicroSplat.TextureArrayConfigEditor:DelayedCompileConfig() (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:871)
    6. UnityEditor.EditorApplication:Internal_CallDelayFunctions()
    7.  
    The easy fix to put something in the Detail and Distance slots (but I understand the compression for the Normal AntiTileArray is higher quality if you don't do this?) Clipboard Image.png
     
  22. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    42
    Hi Jason, I tried to reinstall Microsplat and also press "update" in "MicrosplatConfig" but the "Draw Instanced" flag still causes the terrain to disappear on 2018.3
    Can you please let me know if there's an extra step on how to regenerate the shaders?

    Thanks
     
  23. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Change an option in the top section and switch it back - when you change any of the shader generation options the shader is re-written.
     
  24. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    I could not repro this- though I did find and fix the other bug with the smoothness array not using the correct size.
     
  25. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    42
    yes, that did the trick. All sorted now.
    Thanks for this amazing asset!
     
  26. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    743
    Hi, I've met a strange issue here:
    In the editor, everything looks correctly, but after build, the terrain just become colorful noises:
    upload_2018-12-17_19-14-33.png

    I'm using Unity 2018.2.16f1 and .net 4 equivalent. In linear color space deferred rendering.
    Any ideas what may got wrong?

    Edit: And I found all skybox and the character become partially colorful noises, maybe it's related to rendered texture? cuz the only common aspect between the terrain, the character and the skybox is they all use rendered textures. All the items with local textures are fine.

    Edit2: Found these lines in the output log file, don't know what does it mean:

    ##utp:{"type":"MemoryLeaks","allocatedMemory":29097,"memoryLabels":[{"Default":1048},{"NewDelete":376},{"Thread":8},{"Manager":112},{"VertexData":4224},{"GfxDevice":2368},{"FMOD":640},{"Serialization":40},{"String":1177},{"DynamicArray":4432},{"VR":64},{"SceneManager":480},{"SceneLoad":-240},{"NativeArray":14360},{"Secure":8}]}
     
    Last edited: Dec 17, 2018
  27. studio1h

    studio1h

    Joined:
    Jul 6, 2012
    Posts:
    31
    Hi Jason, I've run into a strange lighting issue with MicroSplat. When baking a scene with 1 directional light (sun), using realtime GI only, scenes look blown out when viewed on my iPhone 6s. They look fine on my Mac and on my iPhone XS, but totally different on the iPhone 6s. Any idea why this is happening with MicroSplat. BTW, this does not happen when using the builtin Unity terrain shader, only when using MicroSplat. Here's a screenshot which shows the issue:



    That screenshot is from a fresh new Unity project with nothing in it except MicroSplat. All default project settings. Just built for iOS and then screenshoted on each device.

    Unity 2018.2.20f1
    Xcode 10.1
    MicroSplat 2.2
    Lighting: gamma

    Please note, I've done this same test with linear lighting and I get the same result. I've also done this test with Unity 2018.3 and get the same result there, as well.
     
    Last edited: Dec 17, 2018
  28. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    Not sure what you mean by local vs. rendered textures.
     
  29. Nitrox32

    Nitrox32

    Joined:
    May 9, 2017
    Posts:
    94
    I just imported Microsplat. I just created my first texture array and all of my texture (X,Y) sizes are back to their original settings. These sizes are too big for my scene. Is there any way for Microsplat to keep the sizes from the terrain editor?
     
  30. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    You set the size in the texture array config and all input textures are scaled accordingly. Or if your talking about the uv scales, there’s a global uv scale as well as a per texture option for it.
     
  31. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    743
    I actually have no idea why this is happening, it was all fine in the last build. But yesterday every build becomes like this.
    The renderTexture thing is only a guess from my limited knowledge of rendering. Would like to get some advice from you that what may cause microsplat behave like this? And what's the meaning for the output lines I've attached in the Edit2
     
  32. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    None of this has anything to do with MicroSplat. From your discord, it sounds like you've blown past the 4gb limit on Resources and are getting memory corruptions from it.
     
  33. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    342
    What is the state of MicroSplat support for terrain instancing in 2018.3? The texture array copy bug etc etc should have been fixed by Unity, but I still get invisible terrains as soon as I switch on instanced terrains. I also get the following error message:
    Screenshot 2018-12-18 at 14.25.56.png
    As you can see, this is on Mac/Metal.
     
  34. Bodyclock

    Bodyclock

    Joined:
    May 8, 2018
    Posts:
    107
    It works, you just have to recompile the shader by changing an option then change it back again. Check the Discord channel for more details. And there is a new version yesterday with this update amongst others "- Instancing code for 2018.3 now generated even when not running in 2018.3 for easier upgrading". Not sure about Metal though.
     
    PeterB likes this.
  35. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    743
    After a day's research and testing, it does seem like a Resources 4gb limit issue. Trying to use asset bundle instead of Resources for my graphic resources now and see if it can fix the issue.
     
  36. ellioman_flashbulb

    ellioman_flashbulb

    Joined:
    Jan 17, 2017
    Posts:
    7
    Hi Jason,
    Wanted to check if you had given XBox a try with MicroSplat with the new instanced rendering enabled?

    I've been given the task of updating our game to 2018.3 and right now I'm looking at our terrains.

    MicroSplat 2.2 works fine in the editor with instanced rendering turned on or off but on a XBox build the terrain disappears with the instanced mode enabled but renders just fine with it disabled.

    Any idea what could be the culprit? I've updated all of our MicroSplat assets (MicroSplat, AntiTile, TerrainBlending, Tesselation, TextureClusters, Triplanar and Winds&Glitter) and recompiled the shaders we're using.

    Let me know if I can do some testing to help out. The tests I've done so far:
    • Terrain normal rendering: With MicroSplat => Works fine
    • Terrain normal rendering: With Standard Unity => Works fine
    • Terrain instanced rendering: With MicroSplat => Terrain Invisible
    • Terrain instanced rendering: With Standard Unity=> Works fine
     
  37. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    I don't have an XBox dev kit available, so no way for me to test that. The code for instanced rendering is copied almost verbatum from Unity's terrain shader source (the input variable name is different, but otherwise 1:1).
     
  38. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    342
    I've installed the new version and recompiled the shader, but I still get invisible terrains under Metal. Am I alone in this or is anybody else also having problems with instanced terrains under Metal in the 2018.3 release version?
     
  39. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    I develop on a Mac, so Metal is the most tested API.. is it just not appearing in the editor? And by recompiling, I assume you mean regenerating it by changing an option?
     
  40. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    251
    2018.3.0.f2.... I had Microsplat working fine with VS standard but to test I updated to VS Pro. Since the change, Microsplat has an error and the terrain disappears when run in the editor. I noticed that the Microsplat script gets disabled which is technically why it is disappearing in the editor. If, while running in the editor I re-enable the script it appears again but another set of this error appears. If built, it is also a problem on device.

    NullReferenceException: Object reference not set to an instance of an object
    MicroSplatTerrain.RestorePrototypes () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:245)
    MicroSplatTerrain.Sync () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:208)
    MicroSplatTerrain.OnEnable () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:53)

    NullReferenceException: Object reference not set to an instance of an object
    MicroSplatTerrain.RestorePrototypes () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:245)
    MicroSplatTerrain.Sync () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:208)
    MicroSplatTerrain.Awake () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:44)
     
  41. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    743
    Hi, I've met an issue lately with microsplat: if I use none variants (meaning only use one variant) on my shader, the whole terrain become black.
    My settings are like this:
    upload_2018-12-20_11-50-31.png

    and the result is this:
    upload_2018-12-20_11-50-57.png

    If I use two variants all will be fine. Any ideas why this is happening?
    Using unity 2018.2.16f1 and the behavior happens in editor.

    Edit: and found a new strange behavior when using three variants, this error shows up:
    ArgumentException: Could not find MaterialProperty: '_ClusterDiffuse3', Num properties: 26
    UnityEditor.ShaderGUI.FindProperty (System.String propertyName, UnityEditor.MaterialProperty[] properties, System.Boolean propertyIsMandatory) (at C:/buildslave/unity/build/Editor/Mono/Inspector/ShaderGUI.cs:51)
    UnityEditor.ShaderGUI.FindProperty (System.String propertyName, UnityEditor.MaterialProperty[] properties) (at C:/buildslave/unity/build/Editor/Mono/Inspector/ShaderGUI.cs:40)
    MicroSplatShaderGUI.FindProp (System.String name, UnityEditor.MaterialProperty[] props) (at Assets/MicroSplat/Core/Scripts/Editor/MicroSplatShaderGUI.cs:22)
    JBooth.MicroSplat.MicroSplatTextureClusters.DrawShaderGUI (MicroSplatShaderGUI shaderGUI, UnityEngine.Material mat, UnityEditor.MaterialEditor materialEditor, UnityEditor.MaterialProperty[] props) (at Assets/MicroSplat/TextureClusters/Scripts/Editor/MicroSplatTextureClusters.cs:162)
    MicroSplatShaderGUI.OnGUI (UnityEditor.MaterialEditor materialEditor, UnityEditor.MaterialProperty[] props) (at Assets/MicroSplat/Core/Scripts/Editor/MicroSplatShaderGUI.cs:171)
    UnityEditor.MaterialEditor.PropertiesGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/MaterialEditor.cs:1601)
    UnityEditor.MaterialEditor.OnInspectorGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/MaterialEditor.cs:392)
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, System.Int32 editorIndex, System.Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1367)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    and the terrain looks like this:
    upload_2018-12-20_11-55-13.png

    I've checked the texture arrays, they look normal.
     
    Last edited: Dec 20, 2018
  42. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    743
    And if I use this mask for my three variants:
    upload_2018-12-20_12-7-32.png

    The terrain will look like this:
    upload_2018-12-20_12-7-43.png

    Seems the third variant or the last variant got wrong. I've tried to regenerate the texture arrays and reimport all microsplat assets, no help.
     
    Last edited: Dec 20, 2018
  43. eaque

    eaque

    Joined:
    Aug 20, 2014
    Posts:
    596
    Hi,

    Question dealing with the modules. Is it possible to use blending module it with VS for stones (so quite a few stones on a big map)? Or Is it better to use your vertex painter shader to redo the stones?

    thanks
     
  44. ellioman_flashbulb

    ellioman_flashbulb

    Joined:
    Jan 17, 2017
    Posts:
    7
    After further debugging I've found out this has to do with our complicated setup and not MicroSplat.
    Sorry for the troubles.
     
  45. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    382
    @jbooth Hey bro, I'm also getting this error in 2018.3

    NullReferenceException: Object reference not set to an instance of an object
    MicroSplatTerrain.RestorePrototypes () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:245)
    MicroSplatTerrain.Sync () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:208)
    MicroSplatTerrain.SyncAll () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:332)
    JBooth.MicroSplat.TextureArrayConfigEditor.CompileConfig (JBooth.MicroSplat.TextureArrayConfig cfg) (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:1565)
    JBooth.MicroSplat.TextureArrayConfigEditor.DelayedCompileConfig () (at Assets/MicroSplat/Core/Scripts/Editor/TextureArrayConfigEditor.cs:873)
    UnityEditor.EditorApplication.Internal_CallDelayFunctions () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:209)

    I'll try and get you some more data to go on, but currently it has me stumped
     
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711
    I've got a few reports of this bug no repro. Only happens in builds or play mode right?
     
  47. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    382
    No it happens in editor also, It happens when ever i click update on the texture array config and when ever i hit sync. when you go to paint textures none of the textures show up. if you add a texture and the hit sync the new texture dissapears and the previous textures will then show up again. i think it started when i changed the texture size to 2048, using fastest packing mode not certain tho. Then if you hit play the Micro splat script gets disabled on the terrain and it goes pink. Back in editor mode, you have to re-enable Micro splat to get the shader back, but then you get the same problem with editing textures etc. I'll try and isolate it and send you a repo
     
  48. reapblindhack

    reapblindhack

    Joined:
    Mar 27, 2015
    Posts:
    2
    Thanks for the great tools. Really solid work & well maintained + generously priced. Much appreciated.

    I'm using Unity 2018.3.0.f2 and the newest version of microsplat (and extensions). Getting an error when syncing terrains which causes various other issues. Same (similar?) error as holdingjason & punk above. Figured out where it's happening approximately.

    See the error below:

    NullReferenceException: Object reference not set to an instance of an object
    MicroSplatTerrain.RestorePrototypes () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:245)
    MicroSplatTerrain.Sync () (at Assets/MicroSplat/Core/Scripts/MicroSplatTerrain.cs:208)
    MicroSplatTerrainEditor.OnInspectorGUI () (at Assets/MicroSplat/Core/Scripts/Editor/MicroSplatTerrainEditor.cs:190)


    Unity terrain throws some errors too if you go to paint textures.

    To reproduce it:
    Make new unity terrain, add micro splat terrain script, "convert" to microsplat terrain to generate the shader, setup textures inside microsplat config file and hit "update" to add the texture setup from the microsplat config object into the terrain. Error then shows up anytime it syncs or you hit "sync" and all sorts of weird behaviors.

    To avoid it & cause no errors:
    Make new unity terrain, add microsplat terrain script, "convert" to microsplat terrain to generate the shader, setup the textures for the terrain inside the Unity Terrain object's layer manager, go to the microsplat config object and hit "grab from scene terrain", finish setup of textures in there, hit "Update". Everything works great, no errors at all.

    Please let me know if you can't reproduce this and I'll go deeper into finding what may be causing it in my project. Thank you.

    *edit* to clarify ... Error happens in editor, not in play mode.
     
    punk likes this.
  49. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,711

    Ok, I could not get your exact repro to work- however, I did find an issue that was causing it to not update the prototypes. If you could replace the code block in RestorePrototypes with this one and let me know if it fixes the issue. If so, I'll update the asset store version (*unfortunately they are off for the next week, so no patches will go through)

    Code (CSharp):
    1.  
    2. #if UNITY_2018_3_OR_NEWER
    3.                var protos = terrain.terrainData.terrainLayers;
    4.                bool needsRefresh = false;
    5.                if (protos.Length != count)
    6.                {
    7.                   needsRefresh = true;
    8.                }
    9.                if (!needsRefresh)
    10.                {
    11.                   for (int i = 0; i < protos.Length; ++i)
    12.                   {
    13.                      if (protos[i] == null)
    14.                      {
    15.                         needsRefresh = true;
    16.                      }
    17.                      if (protos[i] != null && cfg.sourceTextures[i] != null && protos[i].diffuseTexture != cfg.sourceTextures[i].diffuse)
    18.                      {
    19.                         needsRefresh = true;
    20.                      }
    21.                   }
    22.                }
    23.                if (needsRefresh)
    24.                {
    25.                   Vector4 v4 = templateMaterial.GetVector("_UVScale");
    26.  
    27.                   Vector2 uvScales = new Vector2(v4.x, v4.y);
    28.                   uvScales = MicroSplatRuntimeUtil.UVScaleToUnityUVScale(uvScales, terrain);
    29.  
    30.                   protos = new TerrainLayer[count];
    31.                   for (int i = 0; i < count; ++i)
    32.                   {
    33.                      TerrainLayer sp = new TerrainLayer();
    34.  
    35.                      sp.diffuseTexture = cfg.sourceTextures[i].diffuse;
    36.                      sp.tileSize = uvScales;
    37.                      if (cfg.sourceTextures[i].normal != null)
    38.                      {
    39.                         sp.normalMapTexture = cfg.sourceTextures[i].normal;
    40.                      }
    41.                    
    42.                      protos[i] = sp;
    43.                   }
    44.  
    45.                   terrain.terrainData.terrainLayers = protos;
    46.                   UnityEditor.EditorUtility.SetDirty(terrain);
    47.                   UnityEditor.EditorUtility.SetDirty(terrain.terrainData);
    48.                }
    49. #else
     
    Larzarus and reapblindhack like this.
  50. reapblindhack

    reapblindhack

    Joined:
    Mar 27, 2015
    Posts:
    2
    @jbooth, seems to have fixed it. Thanks for the patch. I'm a little concerned it couldn't be reproduced. I'll post again if I find out more. Thanks again.