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 Carbongrip · Feb 20, 2014 at 02:33 AM · c#camerafpscubesair

Don't draw cubes not touching air?

How can I make unity 3d not draw cubes that don't touch air(I need better fps), this seems to be to much for me but here is the code that makes a area in game. Please if anyone can even just improve my fps it would be awesome.

 public class ResourceSpawn : MonoBehaviour
 {
     public Transform packIce;
     public Transform Ice;
 
     void Start()
     {
         for (int x = 0; x < 40; x++)
         {
             for (int y = 0; y > -30; y--)
             {
                 for(int z = 0; z < 40; z++)
                 {
                     Instantiate (packIce, new Vector3(x, y, z), Quaternion.identity);
                 }
             }
         }
 
         iceSpike();
     }

Also should I be using start or awake to call this code once? I know start is called once and discarded and awake is called before the game is visible I think. Am I wrong?

Comment
Add comment · Show 12
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 mattyman174 · Feb 20, 2014 at 02:57 AM 1
Share

Dude, your trying to Instantiate 48000 Objects all at once.

What are you trying to achieve with this? Some more background information on what your trying to do will help us help you in figuring out Optimizations or other techniques for achieving your goal.

avatar image robertbu · Feb 20, 2014 at 04:07 AM 0
Share

The normal way game engines deal with arrays of cube-like structures is to create a single mesh with cube-like elements within the mesh. Each element is called a Voxel. That is what @Eric5h5 is suggesting. Google "Unity3d Voxels" for some good reading. Here are two references to get you started:

http://unitycoder.com/blog/2012/10/18/voxel-resources-engines-for-unity/

http://www.sauropodstudio.com/how-to-make-a-voxel-base-game-in-unity/

There are ways to improving your arrays-of-game-objects solution, but ultimately you will need a Voxel-based solution if you expect any kind of reasonable performance for the number of cubes you are creating.

avatar image AlucardJay · Feb 20, 2014 at 04:42 AM 0
Share

http://studentgamedev.blogspot.no/2013/08/unity-voxel-tutorial-part-1-generating.html

avatar image robertbu · Feb 20, 2014 at 05:37 AM 1
Share

Voxel systems delete and place blocks by modifying the mesh. @whydoidoit's comment is point out that Unity has a limit of 64$$anonymous$$ vertices per mesh. That means that each game object will have a maximum number of voxels. I'm guess that most voxel systems build their cubes out of 24 vertices (to allow the use of independent uvs for texturing of all sides). That means each game object will have around a maximum of 1700 cubes. You will need multiple meshes/game objects in order to get the 40$$anonymous$$+ cubes you want.

Given what you are doing, it might be possible to play some really elegant games. You really only need voxels for visible cubes. As you are finding out, what you are attempting to do is not easy to do right.

avatar image robertbu · Feb 20, 2014 at 08:05 PM 1
Share

Hiding is easy. You can turn the renderer off:

 renderer.enabled = false;

or you can deactivate the whole game object:

 gameObject.SetActive(false);

But you are going to have to be able to find which objects to disable. Usually this is done by placing the game objects in an array and then running through the entries in the array. Given your cubes, you can map your array indexes to world positions and avoid going through the whole array.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by Carbongrip · Feb 20, 2014 at 10:28 PM

Ok I am making a new question thats more specific and has a basic idea and performance option!

New thread can be found here http://answers.unity3d.com/questions/645261/creating-objects-and-hiding-when-out-of-range.html

Comment
Add comment · 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
0

Answer by Eric5h5 · Feb 20, 2014 at 03:44 AM

As always, don't instantiate a zillion separate objects, use the Mesh class to create mesh chunks.

Comment
Add comment · Show 4 · 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 Carbongrip · Feb 20, 2014 at 03:52 AM 0
Share

Um what? I don't want them to be a single mesh. They need to be separate. I was planning on having chunks that load and unload with a size of 64 wide and 64 long of cubes at scale 1. I can this happen?

avatar image Eric5h5 · Feb 20, 2014 at 04:12 AM 0
Share

Not a single mesh, a series of mesh chunks, since a mesh can have at max ~65$$anonymous$$ vertices. Each chunk can have many cubes in it, constructed as a single mesh.

avatar image Carbongrip · Feb 20, 2014 at 04:15 AM 0
Share

How may I do this? Got any visual examples?

avatar image Eric5h5 · Feb 20, 2014 at 06:00 AM 0
Share

Google "$$anonymous$$inecraft Unity" or similar; lots of topics about this already.

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Weird FPS Camera 0 Answers

I cant see my gun its clipping through my camera 0 Answers

FPS Camera, Camera and Player conflicting... 1 Answer

Move gameobject pivot 6 Answers

Multiple Cars not working 1 Answer


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