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 DeadKenny · Dec 19, 2013 at 06:31 PM · optimizationsoundlagvehicleefficiency

Public, private and getting stuff efficiency question.

Is it cheaper to have something like a sound set to private and have it find the audio source in the assets or if used as public and set in inspector?\

I'm asking because I see things in code examples in the net that use private versions of things that would be much easier to use as public and set in inspector.

Like for example I'm working vehicle sounds and I just want to add the sound via:

 public AudioSource audioSource;


... Will that suck my cpu dry or something? Just need to know in case.

My game:

http://forum.unity3d.com/threads/200629-Omega-Void-WIP

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
Best Answer

Answer by Jamora · Dec 19, 2013 at 07:34 PM

The access modifier has no effect on the CPU. It only sets how visible the variable is at compile time, so you can encapsulate data in good Object-Oriented fashion.

Using public when private would suffice is not the end of the world, but it is bad (Object-Oriented) software design.

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 DeadKenny · Dec 22, 2013 at 03:42 PM 0
Share

Thanks Dudes.

avatar image
3

Answer by Owen-Reynolds · Dec 19, 2013 at 08:49 PM

As far as Inspector vs. hand-loaded:

A lot of old-time programmers have always had to store data themselves, set up a file format, ... and search/read/load everything themselves. They feel odd if they can't bring up the master audio list in NotePad and check/edit it (and there are some advantages.) These people are naturally going to going to use Resources.Load.

The Inspector is doing the same thing. When you drag "arf.wav" into the dogSound variable, Unity is storing something like "var:dogSound, loc: assets/animals/arf.wav, ... " in a file like "scene3.data". When the scene loads, Unity scans that file and looks up and load the assets from Resources, same as hand-coding would do.

If you know the file format, you could write a special-case file+code. For example, I get a lot of color RGB's sent to me. So instead of setting a Color[] Cols; in the Inspector, I read from a file with lines like: "255/127/127 pink". That way I can cut&paste into the file, or send it to someone else to edit. I doubt it runs faster -- probably slower, since there's one extra file to open.

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

20 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

Related Questions

Is this code inefficient? It is causing Lag. 1 Answer

Why does this simple follow script make my game lag? 2 Answers

how to apply "WaitForSeconds" ? Help Me 1 Answer

How to optimize code with one time use booleans 1 Answer

Unity render lag questions 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