Search Unity

How to reduce large overhead for a script with lots of unused references?

Discussion in 'Immediate Mode GUI (IMGUI)' started by jerotas, Nov 1, 2017.

  1. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I have a script that uses about 30 of a class "TriggeredWaveSpecifics" for settings, all named specific for events. Usually you just use one or 2 of them and the rest are unused. Someone with a rather "needy" game may need to place 500 of this script in a Scene, which equals 15,000 references to TriggeredWaveSpecifics, most of which are wasted space because they aren't being used. This can end up costing a lot of space in a build when it gets large like this. Maybe 10% of the size of a build.

    Unfortunately even if I set the unused ones to NULL, when the Inspector renders it, it basically creates a "new" instance of that class *automatically so it can be rendered there*. I figured Nulling it would let me save the RAM but Unity doesn't seem to let that happen.

    Is there a way to take care of this problem without a lot of refactoring (i.e. putting them all in a single list)?
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Update, I guess the Inspector just shows that anyway (default "new" instance) even if it's null. When I press play I can debug that it is null. Weird...