• 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 swordklak · Nov 16, 2011 at 03:14 AM · instantiatelag

Instantiate Lag.

http://www.youtube.com/watch?v=cW1KW7wHVFY

Go to the above url to see what is happening i beleive it will make it easier for you.

C

if(Input.GetButtonDown("Fire1"))

         {
 
          Instantiate(cubePrefab, 
 
                          GameObject.Find("spawnPoint1").transform.position, 
 
                          Quaternion.identity);
 
                          
 
         }


With the following code the only thing it does is creates a cube at the position of spawnpoint1 ive tried a cylander and a sphere also and all do the same thing.

In works but it LAGS like MAD! Can barely move also for the cube i have a texture and one face appears white...

Does anyone know what to do?

Comment
Add comment · Show 5
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 syclamoth · Nov 16, 2011 at 03:24 AM 1
Share

Can you make the spawnpoint an assigned reference in the inspector? So ins$$anonymous$$d of using GameObject.Find (which is slow, but not that slow) you just refer to the object you already know about? See if that speeds it up a bit.

I don't think this is what is causing the problem, though. Something like that would cause a brief (almost imperceptible) hang, but not ongoing lag. I think it has something to do with the object being instantiated.

avatar image Neten · Nov 16, 2011 at 03:25 AM 0
Share

Does it only lag when you instantiate the cube? Can you write the rest of your code so we may have a better understanding of the issue?

avatar image sacredgeometry · Nov 16, 2011 at 04:05 AM 0
Share

Have you tried loading in the transform for the spawnpoint into a variable then using that variable ins$$anonymous$$d of using the find function every time you hit the fire button?

avatar image sacredgeometry · Nov 16, 2011 at 07:49 AM 0
Share

I had another thought, what is your fps looking like before you hit the spacebar?

avatar image swordklak · Nov 16, 2011 at 10:34 PM 0
Share

The thing is the cube creates RIGHT away and then it starts lagging

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Nov 16, 2011 at 11:15 PM

Ok, first of all did you even read the error messages you got there? Because by searching for them i've found this question which explains that this error is generated by PhysX when you have too much objects in the same space / intersecting each other.

Beside the fact that we can't see much in your video since it's not clear when you press your "Fire1" button, it seems that you try to make another minecraft rip-off. You simply have too much cubes there. For that kind of game you have to use chunking the area. Some people think minecraft is a very stupid / simple game but it contains 10 times more advanced technology than a "normal" first person shooter.

You should take a look at the minecraft starter package because with this approach you won't go anywhere.

Comment
Add comment · Show 1 · 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 sacredgeometry · Nov 16, 2011 at 11:20 PM 0
Share

i cant see him spawning too much but yeah they might all be intersecting. In my voxel based game the levels are 64x64 so 4000ish "cubes" and runs at 200+fps on my laptop. That said I have optimised with culling non visible sides and occlusion culling etc ... I cant see that there is enough here even without that to cause a problem, unless hes standing on a massive pillar.

Oh wait thats the same one.

avatar image
0

Answer by Kiloblargh · Nov 17, 2011 at 10:53 PM

• Don't use Instantiate. Use an Object Pool.

• Don't use GameObject.Find. Use GameObject.FindWithTag and only then in Awake(), to assign an object to a variable.

• Don't use transform.position. Use var myTransform : Transform, assign it to the objects' transform in Awake().

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Rigidbody load problem 1 Answer

performance question about particles and instantiating 1 Answer

Animator issue in bullet hell game 0 Answers

What is faster: Instiantitate (gameObject) vs Instantiate(Resources.Load) 0 Answers

Trying to Instantiate() an object without cloning the code 2 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