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 digzelot · Aug 31, 2017 at 01:13 AM · animatorperformancestaticpublic variable

understating memory usage - which would be better?

Hi, I'm developing for mobile - I have an animator controller and many different scripts that are triggering and setting values within this animator controller (player01's anim controller)

right now i have it set up where each script has its own

 private Animator anim;

referencing the player01 anim controller, but I'm wondering if this is a waste of memory - should I just have an AnimatorController script that contains a

 public static animator anim;

? I'm trying to optimize my code, and am wondering which is better on performance.

Thanks for any insight

Comment
Add comment · Show 1
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 kalen_08 · Aug 31, 2017 at 01:24 AM 0
Share

if there's only one animator that your referencing, then go ahead and make it static. makes things easier in some ways

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by digzelot · Sep 14, 2017 at 03:24 PM

as far as memory usage is concerned, Static objects are not instanced, therefor they are faster in code.

https://www.codeproject.com/Articles/15269/Static-Keyword-Demystified

"So using the static keyword will make your code a bit faster since no object creation is involved."

... Are bugs more common when using statics? Probably... so be careful not to misuse them

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

Answer by ooblii · Aug 31, 2017 at 01:43 AM

yes to the first one. no to the second. If you have that many scripts needing a reference to a character's animator controller, you might try making a singleton. Which would be bizarre and most likely a nightmare.

You're pre-optimizing in the wrong place. If you're worried about wasting RAM, look into audio and texture import settings best practice for mobile.

Comment
Add comment · Show 4 · 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 ooblii · Aug 31, 2017 at 01:50 AM 0
Share

I should clarify; bizarre on a player character, not in principle.

But you certainly could (and should, probably?) have one single class on your player character deter$$anonymous$$ing the character's animation behavior, not "many" as it is now.

avatar image digzelot · Aug 31, 2017 at 12:58 PM 0
Share

"yes to the first one. no to the second." - yes use private anim variables, no don't use a static?

I am optimizing everything; textures, bone counts, meshes, code, etc.

It seems wasteful to have any number (x) of private animator anim variables > 1 referencing the same animator controller

avatar image ooblii digzelot · Aug 31, 2017 at 01:33 PM 0
Share

How many scripts are trying to access the animator controller?

The problem I think you'd run into if you made it static is that if you add that script to another gameObject, say player02, they'd both be referencing the same controller, which is bad.

One approach, would be to have an AnimationCenter class which could have a property for the controller:

public AnimatorController Anim {get; private set;}

it's not wildly different then private references to the controller everywhere, but it's cleaner.

A better way might be to have the AnimationCenter handle all of the animating and listen for events to set triggers, receive values, and update the controller.

avatar image digzelot ooblii · Sep 14, 2017 at 03:32 PM 0
Share

thanks - there's no worry about a player 2 issue. this isn't a "static health on all enemies" type of question

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

94 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 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

Performance on 2D only: Animator.Update 1 Answer

Animator Layers performance (No motion) 0 Answers

Is the animator in Unity really that expensive? 0 Answers

Static method performance vs non static 0 Answers

Animator does not show up 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