Accessing trees created with the terrain tool on an individual level?

Hello and thanks for taking the time to read the following thread.

I have been wondering if there is a way to access the trees created with the terrain tool individually.

I’m trying to make it so that the player can interact with any tree that he encounters. The player character would then proceed to cut down the tree trough a mini-game event. Progressive destruction of the tree based on character performance in said event. Remove and replace original tree with stump and upper tree. Finally, apply gravity to upper tree and make it fall to the ground.

That being said, would it be possible to, alternatively, create a tree with the script attached and paint it on the map with the terrain tool? Cause that would be amazing.

Otherwise, is my other real option to build trees as separate individual game objects?
If that is the case, keeping in mind that there will be a high number of trees around the player most of the time, how could I optimize this to avoid wrecking performance?

I am not asking for someone to hold my hand and write my script or write a step by step tutorial. I am simply asking to be pointed int he right direction.

Thank you again.

Yes, you can do this. Check out the TerrainData.treeInstances member found in the terrain data object attached to the terran. Its basically a array that holds all the trees on the terrain.

Heres a link to the same question with some answers and a script. Should point you in the right direction.

Tom’s terrain tools

http://forum.unity3d.com/threads/30299-Tom-s-Terrain-Tools-(update-new-version-released)

Thanks for the answers, they are appreciated!

Unfortunately, I stumbled across a new problem.
To display progressive destruction on the mesh, I thought I would create several different trunks with all the different stages of destruction and swap between them. Problem is, the terrain engine uses trees consisting of only one mesh, so I would have to swap the whole tree. Wouldn’t that make the wind animation jump every time a swap occurs? Is there a way I could transition the animation of a single tree and bring it to be still to accommodate the swaps? Or is there any other way to go about displaying that progressive destruction?

Thanks again!

So you have different models of the same tree, but with deeper and deeper cuts. The wind effect isn’t an animation per se, but just slight changes made to the tree vertices. Try testing it, if the rest of the tree (branches and such) don’t change (just the trunk does), maybe the wind effect will look the same. But I honestly don’t know.

Does the game need to remember your chop efforts on just one tree, or multiple trees? So if I chop on a tree and leave halfway through, move to another and do the same, and so on…does it need to remember I have several trees that are half chopped, and show that?

If you only need to track one tree at a time, you could do this: When the player starts chopping on the tree, replace it with the actual tree model. In your tree model, have an extra ring of vertices at the chop height in the tree. You could scale these inward as the player chops, making the “waist” of the tree where the player chops narrower and narrower. This would only work if you 1) designed your tree yourself, in blender or something, or 2) can script the tree to insert a ring of vertices in the trunk.

I’m probably not explaining this well, and it may not work for you anyway. But imagine a cylinder that represents the tree trunk.
Halfway up the cylinder, imagine a ring of vertices that split it in half vertically. Now just above AND below that, insert another ring of vertices.

As you chop, the middle ring shrinks in scale, inward…looking like you are chopping more and from the tree. When it gets to a certain point, the tree falls :).
Also, you could texture those vertices in the middle to match the tree bark, but when you start chopping replace it with a chop texture.

Anyway…just some thoughts. May not be that great if you need to track a lot of trees in various chop stages, as you are showing regular models instead of terrain trees.

Here’s the thing. If I place the trees trough the terrain engine, they have to be made of only one mesh, therefore i cannot swap only the trunk. If I want to swap something on the tree, I have to swap the whole tree. By swapping the whole tree, I replace the current tree which is already modified by the wind with another tree that is in the default position, creating that said problematic jump.

The game needs to remember the state of each tree. If the player character gets attacked while in the mini-game, he gets ejected and the mini-game saves its current state. The player can then return to the unfinished mini-game and complete it.

The game is in third person view. When you trigger the interaction with any nearby tree, the camera transitions to a first person view to better display the mini-game UI and the trunk of the tree. The player inside the mini-game isn’t the problem, because he can only see the tree trunk while the swaps occur. However, the game supports Co-Op so the second player could easily see them.

To the extent of my abilities, it comes down to this:

  1. If I use trees made in the tree creator (Single mesh trees), I need to be able to gradually nullify the wind animation on a single tree.

-In my opinion, they don’t look that good.

  1. I can create my own trees and use the Advanced Foliage Shader by Forst to make them sway in the wind. I would still need to be able to gradually nullify the wind animation on a single tree, but it might be easier to access than the terrain engine.

-More flexibility in the tree creation.
-Again, in my opinion, I think that foliage shader looks way better.

  1. I decide that wind is overrated and create static trees.

-This is the very sad option.

  1. I come back to read this thread and you guys blessed me with your godly knowledge.

-This is the very happy option.

If I get the last post correctly, I would need to script vertex movement very precisely to match every different destruction level and also change the texture to match the dents in the wood? Could I achieve a high level of detail and precision this way? Plus wouldn’t that be a lot more work?

Thanks again for the replies.

Bumpidy bumpy bump.