Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by fred_gds · Mar 12, 2016 at 07:15 PM · editorperformanceeditor-scriptingcustom-inspector

Editor Scripts running slow

Hello,

I have a lot of scripts that I use to setup stuff in the editor. Mostly CustomEditors. When designing these scripts I am not as much paying attention on whether they are written in the most performant way (like they calculate a value twice where I could just calculate it once).

But even thought that there might be a couple small things I could improve, I still think they should not be stuck somewhere for a long time. When I calculate some stuff it seems to take forever (sometimes a couple minutes for a few thousand calculations).

Is there anything special to pay attention in the Editor?

Like are there any calls I should avoid?

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 Salmjak · Mar 12, 2016 at 09:55 PM 0
Share

@fred_gds There are tons of stuff to avoid in Unity. This is a good introduction to the topic.

I don't know if that article brings it up, but the default comparer for Vector3 (Vector3.Equals()) creates a new Vector3 when it is called. So it is a really bad idea to loop that several thousands of time (a giant garbage generator).

When I worked on pre-processing A* paths I retrieved 22k paths in a couple of $$anonymous$$utes (that's 1-15000 iterations for each path).

You should really post your code so we can help you.

avatar image fred_gds Salmjak · Mar 13, 2016 at 04:23 PM 0
Share

Thanks for your suggestion and the article.

I definitely use a lot of the Vector3.Equals() which might cause the problem. I'll definitely check on maybe calling the garbage collector at key points.

$$anonymous$$y code is kind of long and on multiple scripts so I think it would be way too long to post it here (and it is not that well documented :D ). I just hoped to get some general advise as your suggestion on comparing Vector3 :)

"Another interesting side-effects of the List type is that, even when it’s cleared, it does not release the memory it has allocated (ie. the capacity remains the same). If you have a List with many elements, calling Clear() will not release this memory – it will just clear out its contents and set the count to zero. Similarly, adding new elements to this list will not allocate new memory, until capacity is reached." from the article is definitely a great advise

avatar image Salmjak fred_gds · Mar 13, 2016 at 04:59 PM 0
Share

@fred_gds Yeah. I don't know if the article brings it up but you should always type in an estimated size of the list() (it would look like ... new List<myClass>(1000);. The resize of a list is extremely expensive. What it does is that it creates a new array with a new size and copies all the elements into the new array. This means that nothing will reference the old array any more and it will become garbage.

If you're working on a grid-based position system you can bitshift each of your vector3-components (x,y,z) into a single ulong. This will make it possible to compare them without the memory problems. This may or may not work depending on the size of your positions as well.

0 Replies

· Add your reply
  • Sort: 

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

74 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unable to edit fields from custom inspector 1 Answer

Custom Inspector Script Resetting Information 0 Answers

Gizmo custom Icon tinted by default? 0 Answers

Controlling animation editor programatically 0 Answers

How is my waypoint line going back to the gameobject it is stored in and not to the waypoint 0 0 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