Search Unity

Question Script reverts after unity restart

Discussion in 'Editor & General Support' started by Kryc8, Mar 27, 2020.

  1. Kryc8

    Kryc8

    Joined:
    Dec 1, 2019
    Posts:
    2
    Hello first time poster here!

    I have problems with Lighting 2D. I want some objects to be brighter when I point my cursor at them and I decided that adding 2D light to them would be the best option.

    Code (CSharp):
    1.    
    2.     [SerializeField] private float lightIntesivity = 10.0f;
    3.     private Light2D lighting;
    4.  
    5.     private void Awake()
    6.     {
    7.         lighting = gameObject.AddComponent<UnityEngine.Experimental.Rendering.Universal.Light2D>();
    8.         lighting.lightType = Light2D.LightType.Sprite;
    9.         lighting.intensity = lightIntesivity;
    10.         lighting.lightCookieSprite = GetComponent<SpriteRenderer>().sprite; //<----- error lightCookieSprite is get only value
    11.     }
    Problem is that lightCookieSprite is get only value and I can't change it in anyway other than in inspector which would add problems and force me to change it manualy for every object (and it would be useless anyway for objects that change sprites at runtime).

    I found a solution for my problem by changing line of code in Light2D.cs script from:
    Code (CSharp):
    1.         public Sprite lightCookieSprite => m_LightCookieSprite;
    2.  
    To:
    Code (CSharp):
    1. public Sprite lightCookieSprite { get => m_LightCookieSprite; set => m_LightCookieSprite = value; }
    But it seems to revert back everytime I exit unity.
    Is there any way to make it stay changed?

    Also I found a thread in 2018 talking about problem with lightCookieSprite being get only and someone from unity wrote that they will look into making it more public but it seems that they forgot about it.

    Thanks for help
     
  2. Kryc8

    Kryc8

    Joined:
    Dec 1, 2019
    Posts:
    2
    Well I found out that it's because the script Light2D is in Library folder. Still I have too find the solution.