Using PlayerPrefs to Play Intro Cutscene Only Once

Eric Veciana
3 min readMay 23, 2024

I have a cutscene that I want to play once the player starts the game from the main menu; however, I don’t want the cutscene to play if the player restarts the game. To do this, I used PlayerPrefs to save a specific value and if that value has been saved, then it will not play the scene again. I have also created a method to delete this value so I can play the cutscene again, but only when starting from the main menu.

First, I created a const string in my GameManager. By using a string, it will maintain readability. Using the “const” keyword will make it immutable, meaning it cannot be changed once it’s defined.

Next, I created a coroutine to play the intro timeline, and then once the timeline has finished playing, PlayerPrefs will set the key to an integer of 1 and save it.

Then, in Start, we will first check if we are in the buildIndex of 1, which is the first scene after the Main Menu. If the scene does not have a key assigned to it, it will start the coroutine. If the string already has a key assigned to it, meaning it has been played and saved already, then it will move on to the else statement.

Start method

Finally, I’ve created a method to delete this key that has been saved, and then save it as it. You can add this method wherever you choose to reset the cutscene flag. I placed mine in my StartGame method, which is performed when pressing play from the Main Menu.

This way, if I wanted the cutscene to play again from the main menu I can; otherwise, the key will be saved once and then the cutscene will never play again. This is also a good way to test that it works properly if you want to delete the key and try again for testing.

And that’s all you need!

--

--