1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Saving time by reducing access?

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

  1. EnsurdFrndship

    EnsurdFrndship

    Joined:
    Apr 17, 2010
    Posts:
    712
    Hello,
    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

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    1,710
    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

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    5,680
    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

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    4,937
    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. BoredMormon

    BoredMormon

    Joined:
    Dec 5, 2013
    Posts:
    13,268
    Move classes that don't get changed much into something that compiles earlier.

    https://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html

    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.