Forum rules - please read before posting.

Can path node span sorting groups?

Hi,

I have an existing system for a 2D adventure that I'm looking to massage over to AC. In particular I want to switch over to AC's navigation system.

I have a single large town area. The player is able to go into shops in this town. I manage this by switching the players sorting group during the "enter" and "exit" transition.

My custom solution manages this by having node 1 of my path in the "outside" sorting group, and node 2 in the "inside" sorting group. I run some custom code to that if oldSortingGroup != newSortingGroup then player.sortingGroup = newSortingGroup.

I'd like to ditch this in favour of AC's better system. I wondered if I can extend the node object to provide the sortingGroup of each node. Or am I thinking about this wrong and there's a better way to achieve this?

I was hoping that I could have a generic cutscene I could apply to all path origins and terminals, which accepts a dynamic variable of the target sortingGroup (or is able to check the sortingGroup of the node triggering the cutscene as the first step of the scene), in order to then instruct the player object to switch sortingGroup.

Thanks, and let me know if you want me to give any clarification.
Rob

Comments

  • edited November 2024

    Are you dealing with Path objects to have the characters move in between these different areas? There are a couple of ways you can go about this, if so.

    The first is to define a Cutscene at the various node points you want to make a change to, and then run an Action (custom or otherwise) as needed. Node cutscenes will run when a character reaches a node on a Path. If the ActionList involved has a GameObject parameter, you can also have the node assign this to the character dynamically, so that the Actions can affect different characters depending on who's moving.

    The other way is through scripting: hooking into the OnCharacterReachNode custom event lets you run additional code as a character reaches specific nodes along a Path. Sample code:

    using UnityEngine;
    using AC;
    
    public class PathEvents : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnCharacterReachNode += OnReachNode; }
        private void OnDisable () { EventManager.OnCharacterReachNode += OnReachNode; }
    
        private void OnReachNode (Char character, Paths path, int node)
        {
            if (path.gameObject != gameObject) return;
    
            if (node == 0)
            {
                // Start
            }
            else if (node == path.nodes.Count - 1)
            {
                // End
            }
        }
    
    }
    

    I may be misunderstanding the issue, though. As this is a visual issue, any screenshots you can share will help clarify the situation if so.

  • That's great - thanks Chris. I've got this working via a CustomEvent using a cutscene which is working, but I think it's a little in-flexible, so I'll try by hooking into the OnCharacterReachNode event now - thanks.

  • Ah actually - I've just realised that with the 2nd example, what I really need is to load some custom parameter / metadata off the node itself.

    If I have three nodes, I want to be able to define the sortingGroup per node. That way, OnCharacterReachNode, I can read the SG of that node, and apply it to the moving character.

    Would it be possible to assign some property of some object to each node on the UI and have that available in the "OnReachNode" method?

    https://imgur.com/a/ZpApIkk

  • Not directly - other than the Cutscene object itself.

    What you could do is leave each Cutscene blank, but use the GameObject it's attached to for additional data.

    For example, you could attach each Cutscene to the SortingGroup component you want to rely on, and then extract that from the event hook:

    var cutscene = path.nodeCommands[node].cutscene;
    if (cutscene)
    {
        var sortingGroup = cutscene.GetComponent<UnityEngine.Rendering.SortingGroup> ();
        //
    }
    
  • Thanks Chris, last night I put together a test using markers instead of a path, as markers themselves have a sprite renderer so can hold the sortingGroup metadata I need.

    Now I have a cutscene which executes when the player is entering a shop. It goes marker1 -> 2 -> change player sortingGroup -> 3

    This is the closest to how I need it to work, but is quite a cumbersome solution, plus the markers don't draw a line between them so the UI is quite confusing. But I can live with it for now.

    Re-reading your comment above - so each node of a path can have its own cutscene? Hmm that might work then. Especially if I have a handle of "helper" cutscenes, one per each sortingGroup (there aren't that many). I'll give that a try tonight. Thanks again!

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.