Your comments

If your trees were already set at 250 and/or it doesn't make any difference doing this, you might also check to ensure that your entire scene isn't scaled down to something very small, or something very large. If the scene is scaled at all to anything other than 1:1, you might need to do some tweaking to get it to work right.

Sorry for the late reply. I would check that your LOD is set to the default value of 250, and then click the "recalculate parents" button to ensure that the trees are set up correctly on the LOD level of 250. I know that having a very low LOD setting can cause the scene to take longer to laod, and cause a lot of calls to Start(). If this doesn't fix it, let me know and we'll dig a little deeper to try to figure it out.

The parents can't have children too far away. The way I designed it is, the distance that the parents can handle is directly tired to the LOD distance you set in the manager. When you set the LOD distance high, then the trees start to transition much further away from the camera... which means the parents can handle children further away  from the parent. But when the LOD distance is very small, then the parents also have a very small range for their children, which also increases the number of parents required in the scene.


Reason for this is, if I remember correctly, if you had a huge distance on the parents from their children, but your LOD distance was set really low, then the parent would either turn on some of its children really early (long before you are close enough that those children need to transition, OR... the parent wouldn't turn them on  until they should have already began their transition. Something like that is the problem. So the parent distance is tied to the LOD distance.

Sure I can write a tutorial for you. But for the time being, I'll just tell you real quick.


Adding trees while the game is running works just the same as adding any other prefab to your scene while the game is running, with ONE EXCEPTION...


LushLOD Trees have a system I called "parents". The parenting of the trees is basically this... each tree is linked to the trees around it. And essentially, one will be a "parent", and the other trees around it will be "children". When the camera is very close to the trees, then ALL of the trees that are close to the camera will measure their distance to the camera at frequent intervals, so that they can transition from billboards as necessary.


However, when the trees are far away from the camera, it would be excessive for ALL of them to measure their distance to the camera... as that would be expensive on the processor, especially for thousands of trees. That's what the parents are for. Basically, when the trees are far away, ONLY the parent is active, and ONLY the parent's Update() function will run, and ONLY the parent will measure its distance to the camera (at a less frequent interval too). Then, if the parent detects that the camera is getting close, the parent will "awaken" all of its children, and all the child trees (the trees that are nearby that parent tree) will then start to measure their distance to the camera, so that they can transition from billboards as the camera approaches closer. Hope that makes sense.


Well anyway, so here's what this means for adding trees while the game is running:


1) Anytime you add, delete, or even move a LushLOD Tree while the game is running, the parents need to be fully recalculated.


If I remember correctly, I set it up so that if you add, delete, or move a tree, it will recalculate parents automatically. A warning will appear in the console the first time this happens. Recalculating parents for thousands of trees is very slow, and if it happens after EVERY tree you add, then that's thousands of times that parents will be recalculated.


So basically, all of this was to say, that you need to make sure it doesn't recalculate parents more than once. What you want to do is add all the trees (while the game is running), and then after you're done adding all the trees, then recalculate the parents ONCE. But don't let it recalculate parents after each tree you add. Just do the parents calculation once, after each time you update the trees in the scene.


Okay so in the _LushLODTreesManager.cs script, you'll see a function called something like RecalculateParents(). That's the function that calculates the parents. You basically need to add some of your own code to that function, to PREVENT that function from being run multiple times. Some code at the top of that function which will check to see if your custom code (the code you wrote to add trees to your scene) is DONE making all your changes to the trees. And if you're not done, then just tell it to exit that RecalculateParents() function. Don't let it run the RecalculateParents() over and over again after every tree you update, because that will make it take forever to update your tree. And then, when your custom code is finished add trees to the scene, then you'll just want to manually call the RecalculateParents() function, and let it recalculate the parents. And that's about it, your scene should be good to go.


One disclaimer: It's been a long time since I wrote the RecalculateParents() function. It's possible, I may have actually added some code to let you control when and if it recalculates the parents. I don't *think* I added any such code, and I'm *pretty sure* it will try to recalculate parents after every tree you add to the scene. However, I may have added a delay of a few seconds, so that it'll wait a few seconds before recalculating parents... allowing you some time to add multiple trees before a recalculation of parents occurs. But either way, you'll still want to take direct control of RecalculateParents(), to ensure that function is only called once, after you are fully done.


Let me know if you run into any problems I didn't address above. I may be forgetting some key step, it's been a while since I played around with adding LushLOD Trees to a scene dynamically.

Yikes! Glad you figured that one out.


Maybe I'll check if it is possible for my script to set the tree to non-static just before conversion, to avoid that error from happening. If not, I'll have it give the user a warning if it detects that the tree is static. Thanks for the bug report!

Also I have no idea why the name of the mesh is appended with the (root: scene)(clone) tags. That's kind of odd, I wonder if the tree package you are working with has some kind of other script that is messing with the tree in some way, for it to have those tags on the mesh file.

Well, you could try this:


1) Right click the file for the Tree Creator Tree. Make sure it's not some small part of the tree, but the prefab file that contains the whole unity tree creator tree.

2) Click "Select Dependencies".

3) See if you see any mesh files in the list that it gives you. 

4) Select each mesh file, and see if it is by any chance a FBX file of some sort, with import settings that can be adjusted.


Honestly though, my script never accesses the individual mesh files that make up the tree. The whole tree is converted by the tree creator into a single mesh, and my script accesses the verticies of that mesh. But that single mesh is not any kind of FBX file or with any kind of import settings. Unless under some strange situations the tree creator can produce a tree that has a mesh that has import settings, but I've never seen it do that.


But if none of the above helps, you can still send me your scene with your tree and I'll be able to figure this out for you.

That's strange, I've never seen this error before. My converter definitely edits a mesh, but not the mesh of your original tree, only the new LushLOD mesh that it creates. You might want to try clicking the little "refresh" button on your tree creator tree. It's in the inspector window, and its a really tiny button that's hard to find, it's located along the left side, just at the lower left corner of the "Tree" component. So you first select your Unity tree, and then look at the inspector window, find the "Tree" component, and look at the lower left corner of the tree component, and the little refresh button should be there. That little refresh button looks like a circular arrow. Clicking it will sometimes refresh the textures / mesh of the tree, which can fix all kinds of odd problems with Unity Trees. If that doesn't help, you might even try restarting Unity. 


If none of the above fixes it, would you be able to remove all but one of the trees that won't convert, and then create a package containing the scene and the tree, and send that package to me, so I can try the conversion on my computer and see if I can get the same error? You can create a package by following these steps:


1) Remove all other trees from the scene other than one that is failing to convert.

2) Right click the scene file, and select "View Dependencies",

3) Make a note of all the files that are required, it may be quite a few files related to that specific tree (textures, materials, meshes, etc). I'll need all those files.

4) Right click the scene again, and select "Create Package", and then select the scene and ALL the files related to that tree (which should have been found in step 3), along with any files you may think are needed by the tree which were possibly not shown in step 3.

5) It will create a package file, which you can then upload to drive.google.com or somewhere, and give me a link to download it.

One thing though, the shadows in the leaves are fake and "approximate", so you won't be able to get the exactly perfect edges along the leaves like you see in the tree on the left. So if you do decide to work on this yourself, be aware that the leaves could be given some more contrast, and a blue tint to the shadows, but the edges of the shadows will never be as properly positioned as the tree on the left, since the shadows are approximate. But for the bark, you could get the back side of the bark to have more sharper edge to its shadow and so, for the bark, you could get the bark to look pretty much the same as the tree on the left with some tweaking to its shader.