There are other ways for sure, though not necessarily better.
A boolean guard like you have is perfectly fine for most cases, though note that it is not thread-safe. But unless you’re working with threads you don’t have to worry about that.
thanks, the problem is in this way i have millions of variables at the start of script.
horsecar123 | 2022-05-15 13:19
Can you provide more context on how you’re using these guards? What type of functionality are you trying to achieve?
Rather than examining options for guarding a single method I get the feeling the question should be more about structuring your project to avoid the use of many single-shot blocks of code.
Not to mention something obvious, but if you only want something to run once, don’t run it in process. Process runs every frame. Instead, put what you want to do in a function and run that when you need it to.