Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Avoiding using System with String[]

Discussion in 'Scripting' started by Eidern, Jul 9, 2017.

  1. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    94
    Hello,
    I'm trying to reduce my webGL build for my project ,
    in order to do that i'm trying to avoid using System at all costs (as i've got 2.4mb of textures and 5.4mb of dlls !! )

    But i'm stuck at the beginning:
    I've got a declaration of
    String[] whatevervariable;

    and it seems that just using System.Collections; isn't enough..
    what is the best way to avoid using the whole System dll's? and to control the using of these huge dll's in a project that contents no physics or whatever (it's not even a game :/ )
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Ummm... you sort of can't avoid using System.

    System is where a lot of necessary types exist.

    float, int, bool, string, object, Array, List...

    Yeah, these are all in System. It's sort of integral to your build.
     
    Ryiah and Kiwasi like this.
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Why are you using a Game Engine then?
     
    Ryiah and Kiwasi like this.
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    I think he's trying to avoid using System;

    What I'm curious is why use String[] instead of string[]?

    Next, what is your final build size when you build out the project? If you do have a lot of textures, perhaps consider the crunch compression if you are able. Heck, any compression is better than Truecolor if you can help it for webgl.
     
  5. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    94
    oh because i'm used to making games in unity, and wanted to use some of the features for a webapp with Gmap functions that can easily been converted to phone app. But I hadn't though that web build can be this size. (I guess that even for a web Game 7Mb is way too heavy for most of users)
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    sounds to me like they're trying to avoid the dll's being included in his build.

    And specifically System.dll

    But they're talking about 'String'. Which is in the System namespace... you can't avoid the System namespace. Even if you don't access it, you're indirectly accessing it.

    Now String exists in the mscorlib.dll, this dll MUST be included, there's no ifs/ands/buts about it. Mono doesn't work without mscorlib.dll

    System.dll on the other hand contains several extra classes in the System namespace. Non of which are String. But there's all sorts of stuff in there, one can decompile it to see.

    I've never tried removing dependencies on System.dll (as opposed to the entirity of the System namespace... which again, you can't avoid). I have no idea if Unity themselves have dependencies on the System.dll. There's a lot in there.

    ...

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

    So here it appears it says Unity does not have dependencies on System.dll specifically.

    But like I said.. String is not in that, it's in mscorlib.dll, which MUST be included. You must have a dependency on System.dll elsewhere. Are you using 3rd party stuff? You mention Gmap in your latest post... do you mean the google GMap stuff? Are you using a .net library to integrate with the GMap functionality, it may have dependencies on System.dll as well as System.Core.dll since a lot of web stuff is in there like Uri and what not?

    I also still don't see how Unity is useful for Gmap stuff... you could easily write a webapp in many other much more lightweight frameworks that can be easily ported to mobile as well.
     
  7. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    94
    because I wasn't aware that it made a difference :oops:, now thanks to you I know.
    My final build size is approx. 7Mb with 1.4Mbs of texture and 5Mbs of dlls.
    I haven't purged all the unecesary texture from now, but they're compressed, but it's not the main part of my build as you can see.
    When making little games app I Wasn't really into file size, but now that I'm making for the web I'm amazed by the size
     
  8. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    94
    Oh, it's just because I'm not a programer, I'm doing this on my 'little' spare time and I haven't much time left to learn all the framework libs and so on; So i'm stick to what I use the most, it's little projects, not commercial ones :)
     
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Honestly, 7 mb for a webgl app/game isn't that bad at all. Our live webgl game runs at around 23mb, which is a Facebook game. The nice thing is, only the initial load is slower, after that, it loads as fast as on mobile.

    Heck, Unity has improved greatly their webgl build sizes as it use to be much larger.
     
    TaleOf4Gamers and Kiwasi like this.
  10. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    A 'medium' quality 2 min video on youtube is about 10mb
    You are possibly stressing over nothing
     
  11. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    94
    Ahah, I guess you're both right then :)
    Thank you
     
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    7 MB is nothing.

    But if you are worried about it, split out your textures into an asset bundle. Download the minimum in the build to get your game playing, then stream in the rest while players look at the menu or go through the first level.
     
  13. Eidern

    Eidern

    Joined:
    Mar 29, 2014
    Posts:
    94
    As I've learn today, so now we both know :
    string has no dependencies on System.dll but String (with a capital S) does.
    It may cause some headaches..
     
  14. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    But it doesn't... String (with a capital S) is located in mscorlib.dll. I'm literally looking at it in mscorlib right now.

    If unity is including System.dll over the use of String... there's something else going wrong.
     
  15. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    So yeah, I think it's something else causing it... maybe unity is doing a bad job at not including System.dll

    Since I just made a build of a completely empty game, except for a GameObject containing a single script:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class BugTest : MonoBehaviour {
    5.  
    6.     public long Value;
    7.  
    8. }
    9.  
    No 'string' or 'String' anywhere (noting that String and string are the same thing).

    And it is including both System.dll and System.Core.dll in the build.

    I'm thinking unity is just adding these themselves, maybe UnityEngine.dll had dependencies added in recent versions, and maybe that documentation I linked earlier is outdated.
     
    Eidern likes this.
  16. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Really there isn't much difference (the difference between needing System for String and not for string), but here is an article that talks about it http://programmingwithmosh.com/csharp/difference-between-string-and-string-in-c/
     
    lordofduct likes this.