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 Tornado92 · Oct 09, 2014 at 11:30 AM · instantiateupdatetron

Instantiating lowers framerate

My game is a tron-like game in which there is a trail behind the player and if another player walks into it they die. To do this I instantiate invisible cubes behind the player. This works fine but after a while the framerate starts to get lower and lower if the player is moving. If the player is not moving the frame rate goes back to normal. Is there any other way I could instantiate the cubes without lowering the framerate lowering? Or having a colidable trail?

     void Update() {
         if(rigidbody.velocity.magnitude > 7){
             Network.Instantiate(collidie, transform.position + -transform.forward, transform.rotation, 0);
         }
     }
Comment
Add comment · Show 3
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 Redeemer86 · Oct 09, 2014 at 12:50 PM 0
Share

Can't you destroy the cubes gradually after a certain time interval ?

avatar image Owen-Reynolds · Oct 09, 2014 at 04:59 PM 0
Share

Ins$$anonymous$$d of keying off of speed (it makes one every frame, if you go fast enough?) Why not use distance from last place you spawned one? That would help keep the number down. They can even have small gaps between them (too small for other players to go through.)

avatar image Tornado92 · Oct 09, 2014 at 11:09 PM 0
Share

@Harshad$$anonymous$$ I already looked through those and they work but I found that in my game the player can move too fast and pass through the trails without being registered if I use the solutions they mentioned.

@Owen Reynolds I might give that a try. It sounds like it might just work!

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tanshaydar · Oct 09, 2014 at 12:57 PM

I am guessing you are using a prefab (collidie), add a script into it,

 void Awake() {
      Destory(gameObject, 5);
 }

this will destroy your cube after 5 seconds, and your memory won't be filled with old objects.

If you create them too fast, without a time limit between two instantiate time, you need to add that too.

Lastly, you may want to look into polling.

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 Tornado92 · Oct 09, 2014 at 11:05 PM 0
Share

I need the cubes to stay there. The problem isn't that there's too many cubes it's that the script is getting overloaded. Thanks anyway!

avatar image
0

Answer by Kiwasi · Oct 09, 2014 at 11:24 PM

Instantiate is a slow, expensive function. Get used to it. Destroy will also cause you problems.

The best solution is object pooling. Google it. Or check out some of the premade scripts on this answer.

http://answers.unity3d.com/questions/765574/can-someone-just-post-a-generic-object-pool-script.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

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

6 People are following this question.

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

Related Questions

Stop Object from instantiating multiple times in Update using bool 1 Answer

Instantiating road pieces without any spacings between 2 Answers

Some objects are not destroyed/instantiated 0 Answers

Checking if object intersects? 1 Answer

Keep constant number of prefabs 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