Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Saving time by reducing access?

Discussion in 'Scripting' started by EnsurdFrndship, May 19, 2017.

  1. EnsurdFrndship


    Apr 17, 2010
    I notice that AS I add more C sharp classes and scripts to my game, the longer it takes for Unity to compile all the scripts all together probably because each script can 'communicate' between all the other scripts (like how if I call a 'class.functionName()', and the function name is not found within the other script, the compiler generates errors). What if I want to 'limit' what gets 'accessed' between what scripts (to save compile time)? Other times, Unity freezes, and when I re-open Unity, minutes later, I see a dialog box that says, "Hold on compiling scripts." I believe it would save a lot of time and that from happening a lot, IF I could control what scripts can communicate. Is there a way to do this? Thanks.
  2. Brathnann


    Aug 12, 2014
    I don't really understand the question, but if you're worried about compile time, you're worried about the wrong thing. It's hard to say if there would be a better structure for your code without seeing it, but if scripts have to talk to each other, you just have to accept that. As a project grows, it may take longer to compile or build.
  3. StarManta


    Oct 23, 2006
    You can make more members/methods "private" which would limit their access, but I'm not sure whether that would actually affect compile time. Limiting member access is good coding practice, though, as it makes your classes perform more reliably (e.g. you won't accidentally change someNumber to a value that's inappropriate for that number to be, without going through the proper get/set functions). You can google 'encapsulation' for more info/discussion.
    KelsoMRK likes this.
  4. KelsoMRK


    Jul 18, 2010
    Demoting access won't have a huge impact on compile time and isn't a good reason for that decision anyway.

    If you can identify a chunk of your code that is slow moving (doesn't change often) then you can move it into a DLL and place that in your project.

    There have been a few threads about Unity improving their compilation by only doing deltas etc but to me the bigger win would be getting up to date with Mono/.NET and using the Roslyn compiler as a service
  5. Kiwasi


    Dec 5, 2013
    Move classes that don't get changed much into something that compiles earlier.

    Plugins is typically used for this purpose. It will only recompile the folder if it changes.

    Controlling access between scripts is irrelevant to compile time and won't help out at all.