Forum rules - please read before posting.

Changing shader properties with actions

Hello!

Is it possible to change properties of a shader made by Shader Graph with actions? I couldn't find a thread for this, so apologies if this has already been addressed. I have a case where I'd like to "bend" the horizon in a similar way as in Animal Crossing (like in this tutorial: ). The horizon would be straight, but during a cutscene it would bend. In the tutorial the bending effect is controlled by a vector 1 property titled "Amount". So I'd like to know how can I control this property using actions.

Comments

  • edited July 2021

    Updating a material Vector1 property is a case of calling its SetFloat function - see Unity's docs on this here.

    A tutorial on writing custom Actions can be found here. A custom Action could be used to update a material property, but I'm assuming you'd want to be able to update the value over time / transition between your two modes.

    Perhaps a better approach would be to use an Animator's Float parameter to control the effect, and have a script simply sync this with the property, e.g.:

    using UnityEngine;
    
    public class Example : MonoBehaviour
    {
        public float propertyValue;
        public string propertyName = "MyFloat";
        public Renderer rend;
    
        void Update()
        {
            rend.material.SetFloat(propertyName, propertyValue);
        }
    }
    

    Create a new GameObject and attach the script above. Assign the Renderer to affect in the Inspector, as well as the name of the Vector1/Float. Test progress by running the scene and updating the component's Property Value field to check that it affects the material correctly.

    Then, attach an Animator component to the same object as the script, and create animations that control the Property Value field based on what animation is being played. You can then use the Object: Animate Action to control playback, and - in turn - the material.

  • Wow, this is great, thank you! It never crossed my mind that I could use animations for this :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.