What are Asserts for?

It is new in Unity. Here.

What is it for? I don’t know how to use it. Can anyone give an example where this would be useful? Thanks.

Assertions are used to check your code to make sure it’s doing what you intended it to do.

Let’s say you’re making an RPG and wearing armor is supposed to reduce incoming damage, right before the code that deals damage, you could put an assert to check if the incoming damage did indeed get reduced if the character is wearing armor.

It may be similar to just placing an if check, but the point here is to catch errors in the code that should not be there in the first place, i.e. bugs. It’s a way to catch these bugs right there and then as they happen. With an Assert, you’re making an assertion that the code works how you wanted it to.

It may seem silly to have to bother adding a check to code that you wrote yourself, but for a team of programmers, where someone else might end up editing code that they didn’t write, this is useful to make sure they didn’t break anything.

It’s also useful even if you’re working alone and you’re editing code you wrote perhaps months ago, the assert helps to make sure that you didn’t break anything.

Assertions are different from catching erroneous user-input. Errors in user-input are to be expected/anticipated. So usual if checks should be used there, not asserts.