Forum rules - please read before posting.

Joystick breaks entering new scene

Hi everyone,

I have an onscreen gamepad/joystick canvas.

I used to have the joystick in every map, however I wanted it to stop appearing over AC's subtitles while the game is paused so I attached to AC's Menu system (Unity Prefab) and made it appear during gameplay, then deleted all the original joysticks in all the maps.

It works, however every time I change scenes the joystick breaks, meaning you can still move it around but the player doesn't move and it looks really glitchy. It's still active/enabled in Hierarchy though.

I wasn't sure how to go about this so was looking for help!
Thank you :)

Comments

  • The glitching looks like a re-draw issue, where that portion of the screen isn't being cleared properly. This may be down to the joystick, rather than AC specifically.

    However, you needn't move it to the Menu Manager to prevent it from showing during cutscenes. A local object can be set to hide during this time by hooking into the OnEnterGameState / OnExitGameState custom events:

    using UnityEngine;
    using AC;
    
    public class GameStateEventExample : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnEnterGameState += EnterGameState;
            EventManager.OnExitGameState += ExitGameState;
        }
    
        private void OnDisable ()
        {
            EventManager.OnEnterGameState -= EnterGameState;
            EventManager.OnExitGameState -= ExitGameState;
        }
    
        private void EnterGameState (GameState gameState)
        {
            if (gameState == GameState.Normal)
            {
                // Enter gameplay, show the joystick
            }
        }
    
        private void ExitGameState (GameState gameState)
        {
            if (gameState == GameState.Normal)
            {
                // Exit gameplay, hide the joystick
            }
        }
    
    }
    
  • edited September 2022

    Thank you Chris! I attached it to my Joystick UI gameobject, I think I've done it wrong though

    using UnityEngine;
     using System.Collections;
    using AC;
    
    public class GameStateEvent : MonoBehaviour
    {
    
          private Canvas CanvasObject; // Assign in inspector
    
    
    public void Start()
    {
         CanvasObject = GetComponent<Canvas> ();
    }
    
        private void OnEnable ()
        {
    
            EventManager.OnEnterGameState += EnterGameState;
            EventManager.OnExitGameState += ExitGameState;
        }
    
        private void OnDisable ()
        {
            EventManager.OnEnterGameState -= EnterGameState;
            EventManager.OnExitGameState -= ExitGameState;
        }
    
        private void EnterGameState (GameState gameState)
        {
    
            if (gameState == GameState.Normal)
            {
              CanvasObject.enabled = CanvasObject.enabled;
            }
        }
    
        private void ExitGameState (GameState gameState)
        {
            if (gameState == GameState.Normal)
            {
                // Exit gameplay, hide the joystick
                   CanvasObject.enabled = !CanvasObject.enabled;
            }
        }
    
    }
    

    It disables on the subtitles like needed but then when its finished it enables and disables again?

  • Set the enabled value explicitly:

    private void EnterGameState (GameState gameState)
    {
        if (gameState == GameState.Normal)
        {
            CanvasObject.enabled = true;
        }
    }
    
    private void ExitGameState (GameState gameState)
    {
        if (gameState == GameState.Normal)
        {
            // Exit gameplay, hide the joystick
            CanvasObject.enabled = false;
        }
    }
    
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.