While our game may be running without any issues in the editor or even in…
Static Keyword Explanation
The static keyword meaning can differ between functions and variables:
- A static function in a class means that you don’t need to create an actual instance of a class to access a specific function which is marked as static
- A static variable inside a class means tha exactly same thing. However, sometimes you can declare a static variable inside of a specific function. This means that the specific variable is going to get initialized only the first time the function is executed, and every time after that it’s going to hold on its value even if we change it.
Creating a Static variable
To demonstrate the use of a static variable I created an Actor and in the Tick function I typed in the following code:
Create a Blueprint which inherits from TickingActor and place it into your level. Your output log should now contain:
Note:In this case, if you execute your code again the variable x is going to start from the value it had the moment you stopped playing.
This Post Has 0 Comments