Search Unity

Simple Fence Builder

Discussion in 'Assets and Asset Store' started by smada-luap, Oct 14, 2015.

  1. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    This has now been released on the Asset Store

    It's something I've been working on for a little while now (WIP thread is here), and came about because of the time I realised I was spending trying to position prefabs to create fences around my terrains and I thought that there must be a quicker, easier way of doing this and also allow me to create something procedurally that I found tricky to get looking 'right' doing it manually.

     
    Malbers and Gozdek like this.
  2. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,146
    That's very clever and great !!!
    6R
     
  3. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Thanks.

    It's one of those things that you develop for your own needs, show it to a few friends who come up with other suggestions and it grows from there :)

    Before I knew it they were telling me that I should release this for everyone on the Asset Store as there were others that could get some use out of it.
     
  4. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Version 1.0.1 is now being submitted to the Asset Store.

    I've spent some time updating the assets section of Simple Fence Builder to provide a preview image of prefabs that you're using, as well as other options that can be applied if you so wish. :)

    NewAssetsWindow.jpg

    These extra options allow you finer control over how the prefabs will appear - very useful if you want to create a line of bushes...

    screenshot52.jpg

    ... instead of a fence :), or even a row of houses ...

    screenshot55.jpg

    ... that could sit next to a path in your town/village :D
     
    Shawn67 likes this.
  5. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Shawn67 likes this.
  6. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    To those who have bought this from the asset store recently, I hope you're finding it useful :) Could I ask you to please rate this and if you want to, leave a review? Thanks.
     
  7. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    A minor bug came to light over the weekend if you try and compile a standalone build - it doesn't affect the play mode from within the unity editor. This will be remedied soon and an updated version will be submitted to the asset store.

    Thanks.
     
  8. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
  9. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    This is very interesting asset. It looking at how you placed trees and houses and was think you could also use this to place a large number of troops in lines. The US Revolutionary War comes too mind especially those British troops who only marched in straight lines.
     
  10. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    You can use any gameobject you like :) It was after I'd got it finished that a friend suggested I start a town builder, so just as a quick test I put in a house prefab just to see what happened
     
  11. Shawn67

    Shawn67

    Joined:
    Jan 2, 2014
    Posts:
    2,196
    hmmmm... Wonder who that was... heheh I never have got back to try using it that way, but loved the screenies you showed it being done in.

    Those straight lines date way back. Pretty sure that tactic goes back centuries and think they continued up into at least WWI.. I think that is a good idea for spawning those kind of troop lines though, at least for initial spawns. Not sure how they would work at runtime though, or runtime spawning. Definitely something to play around with if you are doing that type of game.

    The uses of this tool goes WAY beyond fences! Great work @smada luap!
     
  12. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459

    Thanks for the clarification. Every since Gaia came out I have been looking at so many more assets then I would have previously.

    My first thought originally was being able to place guards behind the fence at different intervals.
     
  13. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    Agreed. But since I was looking at that time period it was the first thing that came to mind. The thing I found interesting is being able to place game objects in perfect straight lines or the slight variation.

    Hopefully more people will see that this tool can be used for many more things.
     
  14. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    @longroadhwy Please feel free to post any pics of what you may be experimenting with :)
     
  15. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    To celebrate that Spring is almost here (hurray for slightly warmer weather here in the UK :D ), I've put the asset on sale at a 25% discount for a while.
     
    Shawn67 likes this.
  16. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    You should have a link from your Unity asset to this forum thread to. It seems like not all assets do that for some reason. Gaia has a link from their asset for example.
     
  17. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Thought I had. :confused:

    I'll get the metadata info updated :)
     
    Shawn67 likes this.
  18. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Working on creating a simple area that would form the centre of a town and wanted to fence it off but leave entry points at each of the 4 cardinal points. Created this using a single fence by just adding in a 'gap' piece at regular intervals rather than putting 4 L-shaped fences at each of the corners :)

    The fence model is from @S4G4N 's exterior kit in case you were wondering.

    screen_1920x1080_2016-03-22_21-00-46.jpg
     
    Shawn67 and S4G4N like this.
  19. joe_ftg

    joe_ftg

    Joined:
    Nov 9, 2015
    Posts:
    38
    Thanks for this great tool. One minor change we had to make though:-
    Our terrains have a position offset in y and we found that CreateFence didn't take this into account. We had to edit the SampleTerrain function so that it returned (terrain.SampleHeight(position)+terrain.transform.position.y);
     
  20. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Glad you're liking the tool.

    Hmm... I'll admit that it never occurred to me that anyone would have the terrain at anything other than a zero value of Y :)

    I'll make an update for the store just in case anyone else in the future is in the same position that you are.
     
  21. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    This feature will be useful for me also.

    Any requests for adding GPU acceleration to your tool yet?
     
  22. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    None.

    For one thing I have absolutely no idea on how to do that.

    Basically it's asking unity to instantiate prefabs - so if anyone can point me to anywhere gpu acceleration can help in this regard - along with info on how to possibly do it then I shall take everything into consideration. :)
     
  23. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    v1.0.3 is now live on the Asset Store :)
     
  24. Apolyon6k

    Apolyon6k

    Joined:
    May 5, 2013
    Posts:
    32
    Really like the tool but one thing is preventing me from writing a glowing review and give it all the stars it deserves...

    How do I get more than 10 turns or more than 100 fence pieces? One of these limits prevents me from building really long "fences" alongside my roads. Where are the limits for that and can I change them for my purposes? (And yes, I could just put more builder objects together to connect really long fences but then I would need to edit more then one object if I decide to change the turn of my fences.)

    Some of the roads through my (large) terrain get quite long and they tend to twist and turn around a lot as well. If I am using Simple Fence Builder for fences along one of these roads I run into limits, so for one road I had to switch from fences to road markers (every 5 m one marker) to follow the limited turns and the length of the road, unfortunately the same option was not available for another fence along another road...

    Another thing I noticed, was that I could not "mirror" a fence piece within the tool but would have to create a separate prefab for the mirrored fence. This might be fruit for thought on an expansion ;) But it was not something that would prevent me highly recommending the tool :)
     
  25. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Not at the pc at the moment to verify his but they're most likely in the SimpleFenceBuilderEditor.cs file

    The limit for the number of turns is defined in an array if memory serves and the number of fence pieces is set on a range value where the variables are defined
     
  26. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Acutally, I was completely wrong about this, and I blame the amount of time it has been since I needed to be inside the editor code :)

    Anyway @Apolyon6k can you check your PMs?
     
  27. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    v1.0.4 has now been released onto the Asset Store (fixes a minor problem with the undo/redo in the editor)
     
    Shawn67 likes this.
  28. st-VALVe

    st-VALVe

    Joined:
    Jan 8, 2014
    Posts:
    11
    Is there any chance that tool can work with unity 4.6?
     
  29. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    I wouldn't know to be honest as I only have unity 5 installed. I know the prefabs wouldn't translate down and I'm not sure if any of the api calls I've used in the editor ux are unity 5 only or not
     
  30. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    336
    Can it modify the terrain? I was planning to use it to place single object to my terrain and make it modify the terrain to adapt to gameobjects. But as I realized, it can't do it :(
     
  31. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    190
    I just purchased SFB and it works really well but I have discovered a minor bug. If you use a prefab which has it's scale set to anything other than 1, it doesn't calculate the correct distance to offset each fence piece. You have to set the prefab scale to 1, drag it on to the Good Fences spot, create the fence, change the prefab's scale back, then create the fence again and at that point the fence is created with the correct spacing.
     
  32. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Hmm. I wonder if that's a unity thing? Next time I'm on my PC I'll try to remember to have a look to see if there's anything I can do to catch this.

    You might be able to work around this as it stands at the moment though as you should be able to give the prefab in question an override value for the size of the prefab you're wanting to use - I put in this functionality as I was testing it with prefabs that were an empty game object with lots of child objects and when it tried to calculate the size, it couldn't take the size of the child objects into consideration.
     
  33. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    190
    Thanks. One other thing that would be nice is to use the auto rotate function to make a curved section in conjunction with the list of manual turns.
     
  34. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    No promises but if I work out how to include something like this into the existing code then I shall do so. :)

    I have an inkling of an idea that may accomplish this but real life events for the foreseeable future are going to hinder any development time :(
     
  35. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    234
    I've been having a lot of fun with this package. One annoyance however, it does not work with multiple terrain tiles. After some digging and experimentation I have modified the SampleTerrain() method to work with any number of terrains:

    Code (CSharp):
    1.     // Grab terrain information
    2.     float SampleTerrain(Vector3 position)
    3.     {
    4.         if (Terrain.activeTerrains.Length > 1) {
    5.             terrain = null;
    6.             foreach (Terrain t in Terrain.activeTerrains) {
    7.                 Vector3 lowerLeft = t.gameObject.transform.position;
    8.                 Vector3 upperRight = t.gameObject.transform.position + t.terrainData.size;
    9.                      
    10.                 if (gameObject.transform.position.x > lowerLeft.x && gameObject.transform.position.x < upperRight.x &&
    11.                     gameObject.transform.position.z > lowerLeft.z && gameObject.transform.position.z < upperRight.z) {
    12.                     terrain = t;
    13.                     break;
    14.                 }
    15.             }
    16.         } else {
    17.             terrain = Terrain.activeTerrain;
    18.         }
    19.          
    20.         if (terrain != null)
    21.         {
    22.             return (terrain.SampleHeight(position) + terrain.transform.position.y);
    23.         }
    24.         else
    25.         {
    26.             return this.transform.position.y;
    27.         }      
    28.     }
    I basically compare the current object's transform to the lower-left and upper-right corner of each terrain to determine which height to sample. Hope this helps!
     
  36. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Thanks for this. I've never known anyone using this across multiple terrains (or at least they've not informed me :D lol)
     
  37. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    234
    You're welcome! If you have multiple terrains in the scene then Terrain.activeTerrain returns the last terrain loaded in memory, which isn't always the one you're trying to build a fence on. So a lot of the time I was trying to build a fence and the script would put it in the middle of the air or below the ground due to it sampling the wrong terrain tile.
     
  38. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    518
    Hi!

    New customer here.. ;)

    Great job! Very helpful and easy. I'll send you some pics from my game using it.

    Cheers!
     
  39. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Glad you like it.
     
  40. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    170
    Great kit. When multiple terrains are present in the scene the asset does not work properly. It doesn't seem like it can differentiate between the various terrains.
     
  41. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    234
    smada-luap and voncarp like this.
  42. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    170
    Yup. Thats the fix. Thanks!
     
    smada-luap likes this.
  43. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    I'm glad mons00n's solution has helped. I need to get this into an update as soon as circumstances allow.

    Any other problems or issues please get in touch :)
     
  44. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Circumstances allowed this morning :) An update has gone for review and should be on the asset store soon :)
     
    Shawn67 likes this.
  45. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    v1.0.5 is now live on the Asset Store :D
     
    Shawn67 likes this.
  46. GEOMETRICBYTES

    GEOMETRICBYTES

    Joined:
    Aug 23, 2016
    Posts:
    32
    Hi, your asset saved me a lot of time and it is great! But I found a problem with the shadows of the fences. They appear and disappear without reason. Look, in the images from the imgur link that I put bellow, you can see the problem. I only have to rotate the camera just a little and the shadows disappears. The only shadows that doesn't, is from the fence that I put individualy for testing. Please, I really need help with this. Regards, Juan.

    http://imgur.com/a/Nm2En
     
  47. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    Glad you like the asset. As for the shadows I have no clue as to what's happening there as I don't do anything other than instantiate prefabs onto terrains.

    The only thing I can suggest is look at the shadow quality settings, clipping values on your camera and maybe the normal bias values on your light source.

    This may or may not have helped but I hope you can find a solution to your problems
     
  48. GEOMETRICBYTES

    GEOMETRICBYTES

    Joined:
    Aug 23, 2016
    Posts:
    32
    Thanks for the answer! Great support! Ok, clipping planes (far <100) solved the problem. I already knew that. The problem is the game look horrible this way. I use 10000 on far, so the max drawing distance is too close for what I want. Any tip on what can I do to solve the shadow problem?
     
  49. smada-luap

    smada-luap

    Joined:
    Aug 22, 2013
    Posts:
    945
    None that I know of unfortunately
     
  50. GEOMETRICBYTES

    GEOMETRICBYTES

    Joined:
    Aug 23, 2016
    Posts:
    32
    Ok, I found the problem. I deleted the sfb anchor in all the fences I created. Without the anchor the shadows appear and disappear. There are any thing that can I do to fix this? Apart of recreate all the fences again, and NOT delete the anchor... doh!