Forum rules - please read before posting.

brightness option

2

Comments

  • Is this screenshot taken at runtime, and do any messages appear in the Console?

    Try this variant instead:

    using UnityEngine;
    
    public class SetNavCamUI : MonoBehaviour
    {
        void Update ()
        {
            if (GetComponent<Canvas> ().worldCamera == null)
            {
                GameObject navCamUIOb = GameObject.Find ("NavCamUI");
                if (navCamUIOb == null) { Debug.LogWarning ("No NavCamUI object found"); return }
                GetComponent<Canvas> ().worldCamera = navCamUIOb.GetComponent<Camera> ();
            }
        }
    }
    
  • It looks exactly the same at runtime. I used the updated script (there is a missing ; after the "return" for anyone else who reads this), but the console shows no error messages.

    Maybe I set the cam incorrectly/deleted wrong components? Here are screens of its inspector:


  • The Camera component is inactive.

  • I made it active and the result is the same. The menu just doesn't show up.

  • ...it appears when I set its canvas back to Screen Space - Overlay, so it must be something connected to the Screen Space - Camera.

  • This may be a general Unity issue, rather than one related to AC.

    What is the "Plane Distance" field set to, which appears once set to Screen Space - Camera, and with a Camera assigned? This affects how "close" to the camera it is, so it'll need to be a distance that's both closer that the gameplay, but not less than the camera's minimum clipping distance.

  • edited May 2024

    I found the issue. I had the order in layer set as -10; I changed it to 50, and now everything works properly! It didn't occur to me before, because the menu in question normally appeared before i incorporated the brightness option.

    In any case everything works now as it should. Many thanks, Chris!

  • edited May 2024

    So i switched to Universal RP, which made my old setting of brightness option using Post processing stop working. With your valuable tips, Chris, I made it work with this script I stitched together from what you posted here and the link regarding URP you provided (i cannot believe it worked! :-D). I am posting it here for anyone who reads this in the future, although I still have one issue.

    When i move from one level to another, the brightness settings resets. I don't understand why. Can you please advise me on what I am doing wrong?

    • I created an empty object, added a Volume component, created a global profile, and added Override for Color Adjustments (Post Exposure).
    • Added the script below to it.
    • Made the object a prefab and added a constant ID retained in the prefab.
    • Added this prefab into AL in the menu with the slider and in Settings Manager to start with the game.
    • The same prefab was also added to every level.

      using Unity.VisualScripting;
      using UnityEngine;
      using UnityEngine.Rendering;
      using UnityEngine.Rendering.Universal;
      using AC;
      using UnityEngine.Rendering.PostProcessing;
      
      public class Brightness : MonoBehaviour
      {
      
          public Volume volume;
          public string variableName = "Brightness";
          AutoExposure exposure;
      
          UnityEngine.Rendering.Universal.ColorAdjustments colorAdjustments;
      
          void Start()
          {
              volume.profile.TryGet<UnityEngine.Rendering.Universal.ColorAdjustments>(out colorAdjustments);
          }
      
          public void AdjustBrightness()
          {
              float value = AC.GlobalVariables.GetVariable(variableName).FloatValue;
              if (value != 0)
              {
                  colorAdjustments.postExposure.value = value;
              }
              else
              {
                  colorAdjustments.postExposure.value = 0.5f;
              }
          }
      }
      
  • If you're placing a separate instance of the prefab into each level, then only the instance in the currently-open scene will be affected by Object: Send message Actions.

    You can try calling the AdjustBrightness function from your Start function, but it may be best to just rely on a singular instance instead.

    To do this, remove the instances from the scene, and instead use the Events Editor to spawn it in when the game begins - done with Object: Add or remove from the Scene -> Begin game event. To have the prefab survive scene changes, attach the Survive scene changes component to it.

  • edited June 2024

    Chris, I did as you suggested. The brightness setting now stays set when changing among scenes, but I still have an issue (it was there before) that the last set value does not get applied when running the game for the second time or when loading a saved game.

    I am now newly getting an error within the script I posted above on line 27, in public void AdjustBrightness(), specifically:

    colorAdjustments.postExposure.value = value;

    The global variable value "Brightness" is remembered from the previous game on startup (it also shows on the slider position) but is not applied.
    However, this variable value does not change when I load a saved game.

    I have an AL set in Settings Manager to run when I start the game: Object: Send message, which activates the AdjustBrightness function of the script.
    I tried to add this also after the Object: Add in the Event Editor AL, but with no effect.

    I tried to add Variable: Copy to itself (I cannot figure out how else to Get a stored Global variable, but I'm sure Im doing this wrong) and then run Object: Send message: AdjustBrightness as a cutscene on startup/Events editor, but it just threw more errors.

  • What is the error, exactly?

    The Variable's value shouldn't change when loading a save-game - it's part of the Options Data so is independent of individual saves.

    If it's value is correct, it may be an issue with the colorAdjustments variable. Try calling the Start function from the top of the AdjustBrightness function to force its assignment.

  • The error is: NullReferenceException: Object reference not set to an instance of an object.

    I removed the function from Start (see below), and the error disappeared. Now, when the game starts, it remembers the last brightness value. Thank you!

    There is one last thing, tho; when I start a new game by Engine: End Game: Restart game, the brightness setting stops working altogether.

    using Unity.VisualScripting;
    using UnityEngine;
    using UnityEngine.Rendering;
    using UnityEngine.Rendering.Universal;
    using AC;
    using UnityEngine.Rendering.PostProcessing;
    
    public class Brightness : MonoBehaviour
    {
    
        public Volume volume;
        public string variableName = "Brightness";
        AutoExposure exposure;
    
        UnityEngine.Rendering.Universal.ColorAdjustments colorAdjustments;
    
    
    
        public void AdjustBrightness()
        {
            volume.profile.TryGet<UnityEngine.Rendering.Universal.ColorAdjustments>(out colorAdjustments);
            float value = AC.GlobalVariables.GetVariable(variableName).FloatValue;
            if (value != 0)
            {
                colorAdjustments.postExposure.value = value;
            }
            else
            {
                colorAdjustments.postExposure.value = 0.5f;
            }
        }
    }
    
  • Is the object that holds the Brightness script / Volume component still present in the Hierararchy after a restart?

  • It is. This is its inspector - but it looks the same as when the brightness actually works.

  • Is it possible that there are two instances of it, one created each time the game begins?

  • Yes, you are right! I never noticed that... But how?

    To my knowledge, I am spawning it in the On Begin Game Event only. Am I missing something?
    Otherwise, I have an Object: Send a message in several ALs.

  • I restarted two times, and the new Brightness objects spawned every time, so I ended up with three. I suppose it is caused by the On Begin Game Event that just adds the prefab again without destroying the old one?

  • I think i got it, this is my Begin new game AL. The brightness level of the new game stays set from the previous one :)

  • That sounds correct - you can precede the Object: Add or remove Action with another that removes the first.

  • edited June 2024

    Thanks for your help once again, Chris! Just one more, only aesthetical question - is there an easy way for the save screenshots to be saved without the postprocessing effects? So it would always be neutral and not with the current setting of the brightness?

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.