Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by chazman124 · Jan 22, 2012 at 10:05 PM · instantiateprefabsmultiplegrass

Instantiating A Grass Prefab Multiple Times

So I want to instantiate a grass prefab I have multiple times. The goal is to instantiate what will, to the player, look like a field of grass, and then make it cuttable with something like Piecemaker. However, as a person new to coding (although I have a VERY basic knowledge of C++) I'm having trouble getting this done. I've looked into Object.Instantiate, and it might do what I want, but again I'm a noob coder and have very little idea how to use it appropriately. Also, I realize the large amount of system resources that this would probably take up, so if anyone has a different method of creating cuttable fields of grass, please let me know.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jaap Kreijkamp · Jan 23, 2012 at 01:11 AM

Using game objects for every individual patch of grass probably means having lots and lots of game objects, resulting in slow down. I don't know if Unity Terrain engine is an option for you, if so you could make grass detail objects and dynamically update the amount of grass detail in the terrain.

 void UpdateGrass(float x, float y, int ) {
     int offsetX = (x * myTerrain.terrainData.detailResolution / TERRAIN_WIDTH);
     int offsetY = (y * myTerrain.terrainData.detailResolution / TERRAIN_HEIGHT);
     int[,] newDetail = new int[,] { {0} };
     myTerrain.terrainData.SetDetailLayer(offsetX, offsetY, GRASS_LAYER, newDetailAmount);
 }

If terrain engine isn't an option, consider combing the instances of the gameobjects, there should be some examples around on the Unity wiki. If you can't find anything just drop me a note. Of course, combining them makes it a bit harder to remove an individual patch.

If you just want to work with dynamically instantiate the grass and not worry about performance, look in the scripting reference for `Object.Instantiate'. Should give a fairly decent description of how it works.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chazman124 · Jan 23, 2012 at 01:16 AM 0
Share

Yeah, I wrote a pretty crappy script that, for some reason unknown to the world in general, sort of works. It uses Object.Instantiate. And by terrain engine, are you referring to the default Unity terrain engine? And my final noob question is: what do you mean by detail objects? Sorry for my persistent and probably annoying questions, but I really want to learn Unity and learn it well. Thanks!

avatar image chazman124 · Jan 23, 2012 at 01:18 AM 0
Share

Whoops, sorry. Forgot about the Oracle o' Google, and when I googled Detail object I found Detail $$anonymous$$esh. Thanks!

avatar image Jaap Kreijkamp · Jan 23, 2012 at 01:32 AM 0
Share

You already answered the question, it's part if the Unity Terrain Engine. You basically have splatmap (terrain textures), Trees and Detail objects. The detail objects is a way to quickly render lots of detail to the terrain with normally a short distance cutoff. The detail objects are placed procedural, so you have no full control over where a patch ends of exactly within the 'tile' but you say how much detail instances should be in the cell. You have two types of detail, objects, which have a mesh and detail textures/billboards, these generate rectangles with your texture using a transparency shader. This is the cheapest way of adding detail.

The terrain engine isn't available for mobile platforms by the way.

avatar image chazman124 · Jan 23, 2012 at 03:03 PM 0
Share

That's odd. I added my grass prefab to the detail mesh, but when I paint on the terrain nothing happens.

avatar image chazman124 · Feb 14, 2012 at 09:25 PM 0
Share

So I realize it's been a while since I last looked at this thread, but I'm still interested in finding a cool solution to this. I realized that there's a free fake mesh slicer at http://unitycoder.com/blog/2011/08/09/fake-mesh-slicer-v3-0/ which would probably work for cutting the grass, so my questions now are: how can i paint a mesh as if it was grass, and 2: are those meshes actual meshes or are they changed by the terrain engine?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use many particle systems, just varying in size and emitter dimensions 0 Answers

How to instantiate everything inside an Array? 1 Answer

instantiating multiple prefabs within an area (nearly done) 1 Answer

Instantiate Reference Problem 1 Answer

Instantiating Multiple Prefabs at Runtime 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges