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 Dragonsnare0 · Nov 11, 2014 at 05:23 AM · gameobjectdynamic

Memory optimization question

Hi all,

I've been going through the API and haven't ran across any way of doing this yet.

Say I have created a custom prefab using various things. Is there any way to tell how much memory I'm going to be consuming which each spawn of these?

I ask because I'm trying to push my current project to it's limit and had my test machine (Very low end computer) run out of memory multiple times.

I would rather have a calculated result rather than using the trial and error method and having the recompile over and over again and that's not counting the time of transfer and starting on the other machine.

For example let's say I want to spawn a bunch of cubes with rigidbodies, plus textures etc, is there a way I can get a byte readout on the space that single gameobject is going to take up.

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 karljj1 · Nov 11, 2014 at 10:38 AM 0
Share

If you have Unity Pro the profiler will show memory usuage to the level of detail you require.

avatar image Dragonsnare0 · Nov 14, 2014 at 03:39 AM 0
Share

thanks karljj1 so I can't simply place a cube and add a rigidbody then find out how much memory that is going to require. I know how to calculate the textures and everything else.

$$anonymous$$aybe I'm being too vague.

Is there a way to find out the total memory allotment of lets say the rigidbody component? You know it's maximum. I'm sure they didn't just say "hey rigidbody you just go ahead and use all the memory you want sweet thing".

If there isn't a way through script is there a way I can access the code for the components so I can see for myself?

avatar image karljj1 · Nov 14, 2014 at 10:42 AM 0
Share

Using the profiler you can see the infromation you need. $$anonymous$$g see my image, the rigid body uses 108 bytes. You need Unity Pro for this and can also access the profiler data using scripts.

[1]: /storage/temp/35234-untitled.png

untitled.png (58.8 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Immanuel-Scholz · Nov 14, 2014 at 01:03 PM

If you own Unity Pro, the easiest way is the builtin profiler as menitioned in the comments.

If you do not own Unity Pro, you can use System.Diagnostics.Process to inspect the memory of your process. You should wait at least a frame (better some longer) between creation and inspection as Unity may initialize more memory asynchonously.

Here's a first impression on a capture-memory-consumption function could look like (totally untested and written on-the-fly)

 IEnumerable Start()
 {
     var p = System.Diagnostics.Process.GetCurrentProcess();
     long mem = p.VirtualMemorySize64;
     for (int i = 0; i < 100; i++)
         Instantiate(prefab);
     yield return new WaitForSeconds(0.5f);
     Debug.Log("creating 100 prefabs took " + (p.VirtualMemorySize64 - mem) + " bytes");
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to select a gameobject by script dynamically 1 Answer

Fastest way to instantiate thousands of objects at runtime? 1 Answer

Export Game Scene Objects as obj or fbx 1 Answer

Articulation Bodies Vs Rigidbodies in Unity 2020 1 Answer

Find a variable using a string 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