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 harsimranb · Aug 31, 2012 at 03:34 AM · performanceprefabs

Instantiate prefabs to save memory

Hey guys!

I have a 3D world and in that world I want to instantiate people based on the player's location or something similar. I don't want to load all people at once, as that will put load on memory. I've seen that many popular games also do this. I just need guidance on how to accomplish this. I have wayPoints set throughout the game as pathways for people to walk on.

I was thinking maybe create a certain number of people around the player's radius and put them on the random wayPoints inside the radius, then delete people if they are outside the radius. Is this good, or is there a better way? I eventually want this on mobile phones, so performance is a must.

Update: What if I leave all these people in the scene, what kind of performance hit should i expect? They all have scripts, colliders, meshes, etc. They're just walking around, not doing much. But they are large in number, around 500.

Many Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Kryptos · Aug 31, 2012 at 08:09 AM

Don't destroy people this is bad ;)

Joking aside, don't use Destoy/Instantiate because this is bad for memory (and performance). You can create a pool of objects. When a object goes outside the player radius, just teleport it to the other side so that it can enter the radius again.

And to improve performance, try to share as much data as possible between all objects : same material, same texture (use texture atlases), same mesh (and low-poly mesh so that dynamic batching can work).

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 harsimranb · Aug 31, 2012 at 07:18 PM 0
Share

Yeh, I plan to have only about 4 types of people, aside from the main characters....I like your idea...I should instantiate about 50 people and move them if they are outside the radius, using a trigger...I like that

avatar image
1

Answer by landon912 · Aug 31, 2012 at 03:45 AM

You could use occlusion culling to save memory instead of deleting people. If this is not enough then I would just use a big sphere trigger and save the people's current location then destroy them if outside of circle. That way you can spawn them in the exact same spot when you come back

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 harsimranb · Aug 31, 2012 at 04:10 AM 0
Share

occlusion culling is Unity Pro, but I'm using the free version

avatar image harsimranb · Aug 31, 2012 at 04:11 AM 0
Share

So, on the second one, I would store their position and rotation before destroying them and create them again on TriggerEnter? I'm a bit confused, but I want to give it a try...

avatar image landon912 · Aug 31, 2012 at 04:19 AM 0
Share

Yes look at playerprefs in the script reference and you can store there data in that.

avatar image harsimranb · Aug 31, 2012 at 04:36 AM 0
Share

thanks! i'll give it a try

avatar image landon912 · Aug 31, 2012 at 04:53 AM 0
Share

Np pm me if you need help

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

9 People are following this question.

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

Related Questions

How do I optimize memory footprint of multiple pools of similar GameObjects? 0 Answers

Unity 3d CPU Usage on a Macbook Pro 3 Answers

Cloud recognition in Vuforia 0 Answers

Does inactive Objects eat up Performance? 1 Answer

performance benefits of using 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