Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

cleaning obsolete

Discussion in 'Scripting' started by laurentlavigne, Aug 1, 2020.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    3,579
    console showing tons of obsolete API calls with the particlesystem
    Assets\Scripts\TurretBase.cs(321,6): warning CS0618: 'ParticleSystem.enableEmission' is obsolete: 'enableEmission property is deprecated. Use emission.enabled instead.'

    Is it possible to fix these in one line in .NET4.6?
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,013
    Your code is calling obsolete methods/properties. You will need to change the code yourself, fortunately, the error messages are nice enough to tell you the replacement code.
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    3,579
    that's not what i'm asking, i'm asking if this can be done in 1 line instead of 3, because dotnet was updated to 4.6
    var ee = particleSystem.emission;
    ee.enabled = true;
    particleSystem.emission = ee;
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    8,471
    Then you are asking the wrong question.
     
  5. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    3,579
    how so?
    dotnet 4.6 can do things like gameObject?.GetComponent which effectively combines 2 lines in 1
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    3,418
    I'm not sure it's possible to do it in one line, since EmissionModule is a struct. Therefore
    particleSystem.emission
    is always going to give you a copy of the EmissionModule which won't help you change the one actually on the particle system. You could do it with an extra method though:

    Code (CSharp):
    1. EmissionModule CopyWithEmission(EmissionModule original, bool emissionEnabled) {
    2.   EmissionModule copy = original;
    3.   copy.enabled = emissionEnabled;
    4.   return copy;
    5. }
    6.  
    7. ...
    8.  
    9. // Then here's the one-liner
    10. particleSystem.emission = CopyWithEmission(particleSystem.emission, true);
     
    laurentlavigne likes this.
  7. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    3,579
    Ok I thought dotnet4.6 had a shortcut to do that to structs.
    I thought that too but the documentation doesn't seem to mind https://docs.unity3d.com/ScriptReference/ParticleSystem.EmissionModule-rateOverTime.html o_O
    I tried your example and got some red. when I looked inside .emission it's just a getter so
    particleSystem.emission =
    isn't possible.

    enableEmission and WWW are not deprecated in 2020.2 so I might end up disabling 618 and be done with it.
     
unityunity