Create error pop up

I would like to make a feature in my game where if you die, the game quits leaving an error message like the ones that say: “Unity is not responding” but a custom one that says something like: You died. or: you’re too bad for this game or something silly like that. How would I script that?

Buongiorno da Roma!

it’s very simple to do that, and there are plenty of tutorials on youtube, you can search for “Unity UI Popup window” or similar things, on google too. Here an example: https://www.youtube.com/watch?v=LIoNLRoJhoE&ab_channel=DALAB

Shortly to make your “YOU DIED” popup:

  1. Hierarchy
  • Create a Canvas
  • Create a Panel inside the Canvas
  • Create a Text or TextMeshPro inside the Panel
  • Insert “You Died” in the text area of inspector
  1. Code
  • Create a C# Script in project folder and name it “TogglePopup”
  • Create a GameObject variable and name it “popupWindow”
  • Create a bool variable and name it “isOn” and set it false
  • Insert in Start Function this:
popupWindow.SetActive(false);
  • Insert in Update Function this:
if (Input.GetKeyDown(KeyCode.Space))
{
isOn = !isOn;
TogglePopup(isOn);
}
  • Add this Function
public void TogglePopup(bool activate)
{
popupWindow.SetActive(activate);
}
  1. Test
  • In Unity assign the script to an EmptyGameObject
  • Drag and Drop the “Panel” Gameobject from the Hierarchy into the script component popupWindow variable
  • Press Play and press spacebar to toggle it when you want.

Congratulations! you did it. (I scripted this on the fly so meaby can be a syntax error or similar problem, but it shouldn’t)

Now it’s up to you learn scripting or at least a node system, there are free assets on the Asset Store.
Cheers
Carlo

Am I right that you want to quit the game (completely, not to the menu) and show actual system message?

1 Like

Yes. That is exactly what I want.
Is there a way to do that and how?

1 Like

If you just wanted to crash the game, you can always just allocate a ton of memory in a loop for a couple frames until the PC your running it on will crash. IMO that would be the funniest way to do it, but you won’t get any custom messages or anything

I have considered just using application.quit() but people wouldn’t know why the game just crashed, so by leaving the custom error, they know that it’s because they died.

You can call Application.Quit, and then launch some external application or script which will give you the popup. Some external thing is required to outlive actual Unity app being closed. There are plenty of tutorials on how to do something like that.

One of other options is to interact with Windows API while in the game, show popup from the same process and quit game after Ok button click or something.

The rest is experimentation, such uncommon tasks are usually about research and trying different options. You should understand how to quit your game, how to launch external processes or work with CMD, and how to display popup, and then combine it all together. Google how to do specific parts and the rest will become doable.

1 Like

Agreed. Every few months this idea comes along, some variation of “my game is in cyberspace and I want to pretend the user’s computer gets crashed by the enemy virus.”

It’s almost always a bad idea, for one or more of the following reasons:

  • you are far more likely to annoy a user and they will simply instantly uninstall your game and give you a 1-star rating
  • if you really crash the computer, whatever system you’re using to distribute your game might have telemetry that marks your app as untrusted and reduces its ranking until nobody will even SEE your crashing game

So if you insist on pursuing this stuff, make it entirely in game, make your own clearly-labeled “VIRUS CRASHED YOU” popup, display it, let the user accept and return to the menu and reload.

Anything else is just grade school software silliness and will be treated as such by the vast majority of users.

this would be great. How would I do that?

@Bricksmashr10 this would be great. How would I do that?

Google it, literally. I’m not walking Windows/C# encyclopedia.
I think I provided enough information to begin solving the actual thing.
You break down task to small steps, google how to do each one of them and then implement.
I can only reassure you that your idea is much likely possible and isn’t that complex to solve.

Instead of asking for complete solutions, go and solve it. If you have problems which you can’t solve yourself, you can ask for help, but I want to see the actual code, the actual attempt, so I can help you with specific parts you can’t figure out yourself.

1 Like

This technique is invaluable: ask yourself “Can I …?” about each of the parts.

Imphenzia: How Did I Learn To Make Games:

I found this tutorial and copied the first half, I didn’t go into giving it the ability to be clickable through, I designed a window that looked like the windows one and put that in a different scene which loads when you die.

When you click the “OK” button, it just uses Application.Quit()

Thanks everyone for the help :slight_smile:

1 Like