Do I need to always use "override" keyword ?

Hello, recently I noticed that I have this in my custom character .h file:

virtual void BeginPlay();

It compiles fine and it works fine too, so I am just wondering why should I use override keyword there ? Is effect just visual ?

It really just documents your intention and won’t change compilation or behaviour. However it’s a very good idea to always use it. Without it, if you make any slight mistake in the name/signature of the method, you may think you are overriding a virtual function when you are in fact defining a new one. Your project will compile and run, but it will be incorrect and it can be super hard to discover the error.

When you use the override keyword, you get a compiler error if the signature doesn’t match with one in the base class, so you pick up the error right away.

Newer version of clang will fail by default when you use missing overrides.

Another very important note: If you are working, or plan to work with other programmers in the future, always use the keyword. When you read code written by someone else, it is so much easier to see what methods are new and which ones are overridden. So it helps others understand your code better :slight_smile:

Thank you, that’s what I was looking for! I always use override but I found one line in my old code without override and I was like “wtf? why does it work?”.