Hiya,

I want to turn down the light intensity of a 2d light (URP) in a battle event. I tried putting the light inside a prefab and then deactivate/destroy the game object but i cant get it to work. Any tips are welcome!

Thanks
  • I tried using the change field node but no result.

    image

    public class GlobalLightScript : MonoBehaviour
    {
    public UnityEngine.Experimental.Rendering.Universal.Light2D GlobalLightIntensity;

    // Start is called before the first frame update
    void Start()
    {
    GlobalLightIntensity = GetComponent();
    GlobalLightIntensity.intensity = 0.4f;
    }


    }
  • Since you're trying to access a property named intensity, you need a property like that in your script, e.g.:

    public float intensity
    {
    get{ return this.GlobalLightIntensity.intensity; }
    set{ this.GlobalLightIntensity.intensity = value; }
    }
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited January 2021
    Ok i included the property but i still cant seem to change it with the change field node. For testing purposes i connected the script to bolt to check if ik can change the property and that seems to work. Are my settings in the change field node ok? I tried a bunch of settings but no result.


    public class GlobalLightScript : MonoBehaviour
    {
    public UnityEngine.Experimental.Rendering.Universal.Light2D GlobalLightIntensity;
    public float intensity
    {
    get { return this.GlobalLightIntensity.intensity; }
    set { this.GlobalLightIntensity.intensity = value; }
    }

    void Start()
    {
    GlobalLightIntensity = GetComponent<UnityEngine.Experimental.Rendering.Universal.Light2D>();
    GlobalLightIntensity.intensity = intensity;
    }

    }
    Post edited by Anoo on
  • Make sure the target object is correct, i.e. the game object has the component attached.
    Since you're using a Global Object without any key, make sure that the game object you try to access is actually stored in there.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • It's a bit difficult for me to follow but I think I've set it up right.. right?
    This is the game object that i am trying to reach.

    image
  • It's not about the setup of the game object in the scene - it's about the object used by the event.

    Your Target Object in the node is something in Global Objects. Did you store the object into a global object (e.g. in the event) before using the node?

    If not, it might be better to add an Actor to the event and use that, e.g. the Object actor type using Find Object settings to find the game object via the Tag you use for it (GlobalLight).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Ah nice, i get it now! And i got it working adding the search objects node. Is it possible to fade a float? Because now the light intensity just flips on/off.
  • The Change Fields node only sets do defined values, i.e. you'd have to fade that value each frame and set it in the event.

    Alternatively, you can also do the fading in your custom component, i.e. the event just sets the end value and you handle fading e.g. using DOTween or one of Unity's built-in functions.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Alright thanks!
Sign In or Register to comment.