Forum rules - please read before posting.

Highlights not working for URP sprite-lit materials

I can get the highlights working if I use a different material, but then the 2D lighting doesn't work on the object. Any workaround?

«1

Comments

  • The Highlight component's built-in brightness effect occurs by it controlling the "_Color" property of its associated Material. If the sprite involved doesn't have this property, there'll be no visible effect.

    To get around this in URP, you can either use Shader Graph to create a new Material that has such a property (and is used to control the sprite's brightness), or use the Highlight component's event hooks to trigger a separate custom effect. For example, this script on the AC wiki provides integration with the Easy Performant Outline asset.

  • edited March 2022

    I'm not a master in coding but for a 3D project I just changed the highlight script line 61

    private string colorProperty = "_Color";
    to
    private string colorProperty = "_BaseColor";

    And it works.

    I don't know if this:

    #if UNITY_2019_3_OR_NEWER if (GraphicsSettings.currentRenderPipeline && GraphicsSettings.currentRenderPipeline.GetType ().ToString ().Contains ("HighDefinition")) { colorProperty = "_BaseColor"; } #endif

    Could be modified to include the URP?

    I'm not sure how to have similar change for the 2D.

  • Could be modified to include the URP?

    Unsure - IIRC 2D URP is technically separate to "regular" URP. I shall look into it, however.

  • edited March 2022

    Ok so I got the Shader Graph material working, does this look correct? I'm not familiar with the subject. The highlight works as intended with this.

  • I have another question regarding the highlight, I would like that the FlashHotspots function would highlight every interactable object in the scene without worrying about the interactive boundary. How would I go around this?

  • edited March 2022

    does this look correct?

    Looks good to me.

    I would like that the FlashHotspots function would highlight every interactable object in the scene without worrying about the interactive boundary

    You can use a custom script that handles the effect manually based on a separate input:

    using UnityEngine;
    using AC;
    
    public class CustomFlashHotspots : MonoBehaviour
    {
    
        private void Update ()
        {
            if (Input.GetButtonDown ("CustomFlash") && KickStarter.stateHandler.IsInGameplay ())
            {
                foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
                {
                    if (hotspot.IsOn () && hotspot != KickStarter.playerInteraction.GetActiveHotspot ())
                    {
                        hotspot.Flash ();
                    }
                }
            }
        }
    
    }
    
  • Ah, Thank you!

  • @Kisuarts unity2021.3.2 The highlight script failed again.

  • Which script are you referring to - CustomFlashHotspots or the discussed changes to AC's Highlight component?

    In AC 1.75.2 and later, URP's Lit shader should react to AC's Highlight effects.

  • To try and investigate this, I had a test 2D project with the highlights working on unity version 2020.3.23f1 and AC version 1.74.5 (using the both the workaround shader and default materials.)

    They stopped working when I updated AC to 1.75.3

    I made multiple attempts with different materials on different projects and the demos.

    This problem only seems to appear on 2D projects. 3D Works fine with all my tests.

  • Thanks for the details, @Kisuarts, I will attempt a recreation.

    What URP version are you testing with?

  • As a test, open up AC's Highlight.cs component, and find the line block 88-97:

    #if UNITY_2019_3_OR_NEWER
    if (GraphicsSettings.currentRenderPipeline)
    {
        string pipelineType = GraphicsSettings.currentRenderPipeline.GetType ().ToString ();
        if (pipelineType.Contains ("HighDefinition") || pipelineType.Contains ("UniversalRenderPipelineAsset"))
        {
            colorProperty = "_BaseColor";
        }
    }
    #endif
    

    Replace it with:

    string baseColorProperty = "_BaseColor";
    if (affectChildren)
    {
        childRenderers = GetComponentsInChildren<Renderer> ();
        foreach (Renderer childRenderer in childRenderers)
        {
            foreach (Material material in childRenderer.materials)
            {
                if (!material.HasProperty (colorProperty) && material.HasProperty (baseColorProperty))
                {
                    colorProperty = baseColorProperty;
                }
            }
        }
    }
    else
    {
        _renderer = GetComponent<Renderer> ();
        if (_renderer)
        {
            foreach (Material material in _renderer.materials)
            {
                if (!material.HasProperty (colorProperty) && material.HasProperty (baseColorProperty))
                {
                    colorProperty = baseColorProperty;
                }
            }
        }
    }
    

    Does that resolve it?

  • I'm using URP version 10.7.0

    I changed the script and it works for the custom shader and both default sprite material and urp unlit-sprite material, but not urp lit materials for sprites or 3D objects.

  • edited May 2022

    How does that compare with your encountered behaviour from AC v1.74.5 and v1.75.3?

    The issue really comes down to AC trying to predict what material property needs to be controlled - in SRP this is "_Color", while often in HDRP/URP it's "_BaseColor".

    I'm considering reverting this back to "_Color" by default, with an override field you can set in the Settings Manager which - if set - will be used instead. Does that sound like a workable approach to you?

  • I think the behavior is pretty much the same if I recall correctly. I believe the approach you suggested is a good way to go.

  • edited August 2022

    I'm considering reverting this back to "_Color" by default, with an override field you can set in the Settings Manager which - if set - will be used instead. Does that sound like a workable approach to you?

    Hey Chris - this worked perfectly, but wasn't documented anywhere so it took me a while to track down. I am using the Universal Render Pipeline/Lit Shader. I set the AC Game Creator Settings -> Hotspot Settings -> "Highlight material override" to "_BaseColor", and this worked. Thank you!

  • edited August 2022

    Welcome to the community, @JakeT.

    My apologies for the hassle. It is covered in the Manual's "Highlight" chapter, but I agree that it should be made more prominent - thanks for bringing it to my attention.

  • Hi, I'm struggling with the highlight in most of my 3d props. Would it be possible to add a guide in the wiki to know how to add this effect? I saw some tutorials, but they are mainly based on sprites. When I tried to change it to 3D didn't work.
    For instance, one of my objects has 5 different materials. I have no clue about what to do next...

  • edited January 4

    It's a bit open-ended, as the default effect is based on your render pipeline and material.

    What are your AC/Unity versions, what render pipeline are you currently using, and what shader do your Materials use?

    If you can also share screenshots of the Highlight component and the Hotspot it's linked to, I'll see if I can spot the issue.

  • Hi Chris, thanks for your help. This is one of the props I'm using.
    As I mentioned I'm not sure what should I do. Also, those materials are grayed out, like I cannot tweak them.


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.