Skip to content

Basic Scene Fade Manual

codevenient edited this page Feb 1, 2023 · 3 revisions

Introduction

This manual shows you how to fade in at the start of a scene, or fade between scenes in Unity, using our Asset Basic Scene Fade. If you like the Asset, please consider leaving a review in the Asset Store. It will help me a lot.

Installation

Basic Scene Fade is available via the Asset Store.

Fading in at the start of a scene

  1. Locate the FadeInOnStart Prefab in the folder BasicSceneFade/Prefabs and drag it into your scene.
  2. Launch the scene by pressing Unity’s Play button.

You should now see a fade in animation.

Fading to another scene

  1. Locate the FadeTransition Prefab in the folder BasicSceneFade/Prefabs and drag it into your scene.

It is now possible to start a fade transition from a script.

  1. Open the script from which you want to start the transition. Add the following code:
Codevenient.BasicSceneFade.FadeTransition.Instance.FadeToScene("MySceneName");

where MySceneName is the name of your scene.

Instead of using the scene name as a parameter, you can also use the scene’s build index. For example, to fade to the scene with build index 0, use the following code:

Codevenient.BasicSceneFade.FadeTransition.Instance.FadeToScene(0);

Note

  • The transition only works if the new scene has been added to your project’s Build Settings. To open the Build Settings window, select File > Build Settings. To add a scene to the Build Settings, you can drag a scene asset into the “Scenes in Build” list.
  • The above code only works if your scene contains an active FadeTransition Prefab, so please add the Prefab to every scene from which you want to start a transition.
  • When using the above code, it is recommended to have only a single FadeTransition Prefab present in the scene. When multiple FadeTransition components are present, it can be unpredictable which one is used.

Fading to another scene with less code

To start a fade transition with a shorter line of code, you can add the following line of code to the top of your script:

using Codevenient.BasicSceneFade;

Now the fade transition can be started using

FadeTransition.Instance.FadeToScene("MySceneName");

where MySceneName is the name of the next scene. Alternatively, the fade transition can be started using

FadeTransition.Instance.FadeToScene(0);

where you replace 0 by the build index of the next scene.

Fading to another scene without code

You can also set up fade transitions without any code. For example, you can set up a Button which starts a transition to another scene when it is pressed.

  1. Locate the FadeTransition Prefab in the folder BasicSceneFade/Prefabs and drag it into your scene.
  2. Add a new Button to your Scene, by selecting GameObject > UI > Button.
  3. Locate the Button (Script) component in the Inspector.

Note that the Button (Script) component contains an On Click () event.

  1. In the On Click () section, press the + button.

Note that a new field appears in the OnClick () section, where it says "None (Object)".

  1. Drag your FadeTransition GameObject (created in Step 1) from the Hierarchy to the field where it says "None (Object)".

A dropdown menu should now appear, saying "No Function".

  1. Using the dropdown menu, select FadeTransition > FadeToScene (string).

Note the empty textfield that appears in the OnClick () section. We will use this textfield to indicate which scene to fade to.

  1. In the empty textfield, type the name of the scene that you want to fade to.
  2. Launch your scene using Unity’s Play button.

You should now see the button that you created in Step 2. When you press the button, the fade transition should start.

Note

The transition only works if the new scene has been added to your project’s Build Settings. To open the Build Settings window, select File > Build Settings. To add a scene to the Build Settings, you can drag a scene asset into the Scenes in Build list.

Customising the fade effect

To customise your fade effect, select your scene’s FadeInOnStart or FadeTransition GameObject in the Hierarchy and locate its properties in the Inspector. You can edit the following properties:

  • Fade Color: the color used for the fade effect
  • Duration: the time that the fade in or fade out takes, in seconds
  • Delay: the time delay before the fade in, to make the effect look better, in seconds