How to stop Cheat Engine memory cheating in your Unity game
Cheat Engine finds your gold or health value in memory because it is the same number the player sees. Here is how an integer looks in memory, and how a small XOR wrapper in C# hides it.
By Tim UhlottFounder|Last updated: November 26, 2026|15 minutes read
unitycheat engineanti cheat
A player has 1,000 gold in your Unity game. They open Cheat Engine, search for 1000, spend some gold, and search for 850. One address is left. They type 999999 and press Enter.That takes a few minutes, and the player does not need to know anything about programming.On a PC you will not fully prevent this. But the simple way tools like Cheat Engine allow is easy to stop, and that is what this article is about.Let us first look at what Cheat Engine is and why it works on PC games. Then we look at how an integer really looks in memory, and write a small XOR wrapper in C# that hides it from the scan.
What is Cheat Engine?
Cheat Engine (opens in a new tab) is a free, open source memory scanner, mostly used on Windows. It looks into the memory of a running program, finds a value, and lets the user change it while the program keeps running.Memory (RAM) is where your game keeps everything it needs right now, for example the health, the gold, or the position of the player. Every variable in your C# scripts is a few bytes somewhere in that memory while the game runs.Cheat Engine does not need your source code, and it does not need to know what your variable is called. The number the player sees on the screen is enough.I wrote a longer, more technical article about the internals: How Cheat Engine works, and what it actually does. It covers pointer scans, debugging, kernel drivers, and speed hacks. This article stays with the most common cheat, which is editing a value.
How Cheat Engine edits a value in memory
Finding a value is a filter that runs a few times. Let us go through it with the gold example.
The player attaches Cheat Engine to the game process.
They search for the number they see in the game: 1000. Cheat Engine reads the game's memory and lists every address that holds 1000 right now. That can be many thousands of addresses.
They change the value in the game. They buy something, and now they have 850 gold.
They search again, this time for 850. Cheat Engine only checks the addresses from the first list. Almost all of them drop out.
After one or two more rounds, one address is left. That is your gold variable.
They write a new number to that address, or they "freeze" it so it never goes down.
Notice that nothing was cracked or decompiled here. The player only searched for a number they already knew.
Remember: The scan only works because the number in memory is the same number the player sees on the screen.
Why is this even possible on PC?
The short answer is that Windows allows it, and on purpose.A program on Windows can ask the system for access to another program that runs under the same user. Windows has documented functions for exactly this: ReadProcessMemory (opens in a new tab) and WriteProcessMemory (opens in a new tab). Debuggers, profilers, and crash reporters need them to do their work. Cheat Engine uses the same doors.The second reason is simpler. Your game runs on the player's machine. The player owns that machine and is often the administrator, so your game is only a guest there.Consoles and normal phones are different. Each app is locked into its own sandbox, and one app cannot read the memory of another. To get around that, a player has to jailbreak or root the device first. A PC has no such wall by default, which is why memory editing is mostly a PC problem.
Common questions about memory editing
You can make a whole Unity game without ever looking at raw memory. So here are the common questions, with short answers.Can Cheat Engine change a variable in my Unity game? Yes. Any value the game keeps in memory can be found and changed, if the player can see it or guess it.Does a private field help? No. private is a rule for the compiler. It stops other C# code from using the field. In memory, a private field and a public field are the same bytes.Does a C# property protect the value? No. A property is a pair of methods. The value still sits in a field behind it, and Cheat Engine writes to that field directly. Your setter never runs, so a check inside the setter never runs either.What about static or readonly fields? Same answer. They live in memory and can be overwritten. readonly is also only a compiler rule.Does IL2CPP stop Cheat Engine? No. IL2CPP changes how your code is compiled. It makes the code harder to read. An int with the value 1000 is still the same four bytes in memory.Does code obfuscation stop it? Not this cheat. Obfuscation renames and scrambles your code so it is hard to understand. The scan does not care about names. It looks for the number.Does it work on floats and strings too? Yes. Cheat Engine can search for whole numbers of different sizes, floats, doubles, and text. If the type is unknown, the player can search for "value went up" or "value went down" instead of an exact number.Does it work in multiplayer games? Only for values the client decides. If the server keeps the gold and the client only shows it, changing the number on the client changes what the player sees and nothing else.
Takeaway:private, properties, readonly, and IL2CPP protect your code from other code. None of them protect a value from a memory scan.
What an integer looks like in memory
Let us look at the real thing. Here is a normal wallet script:
An int in C# is 4 bytes. The number 1000 is 3E8 in hexadecimal, so with leading zeros it is 00 00 03 E8. PCs store the lowest byte first, which means the four bytes in memory are:
E8 03 00 00
After Spend(150) the gold is 850, which is 352 in hexadecimal:
Gold in the game
Hexadecimal
Bytes in memory
1000
0x000003E8
E8 03 00 00
850
0x00000352
52 03 00 00
When the player picks the value type "4 Bytes" in Cheat Engine and searches for 1000, this byte pattern is what Cheat Engine looks for. The value on the screen and the value in memory match one to one.
Hide the value with XOR encryption
The fix follows from how the scan works. If the number in memory is not the number on the screen, the search finds nothing.The cheapest way to do that is XOR. XOR is a bit operation with one useful property: apply the same key twice and you get the original back.
1000 ^ key = encrypted
encrypted ^ key = 1000
So we store two things, a random key and the encrypted value. We never store the plain number.
usingSystem;publicstructProtectedInt{privatestaticreadonlyRandom random =newRandom();privateint encrypted;privateint key;publicProtectedInt(intvalue){// A new random key for every write. key = random.Next(1,int.MaxValue); encrypted =value^ key;}publicint Value
{get{return encrypted ^ key;}}// Lets you use it like a normal int.publicstaticimplicitoperatorProtectedInt(intvalue){returnnewProtectedInt(value);}publicstaticimplicitoperatorint(ProtectedIntvalue){returnvalue.Value;}}
The two implicit operator methods are the comfortable part. Because of them, the wallet barely changes:
gold -= amount reads the real value, subtracts, and wraps the result in a new ProtectedInt with a new key. The rest of your code keeps working with a normal int.Two small notes. I use System.Random here and not UnityEngine.Random, because Unity does not allow its own random functions inside a field initializer like gold = 1000. And System.Random is not thread safe, so keep this simple version on the main thread.
What the protected value looks like in memory
Let us say the random key is 0x5A3C9F17. With 1000 gold, memory now holds these two fields:
Field
Hexadecimal
Bytes in memory
As a decimal number
encrypted
0x5A3C9CFF
FF 9C 3C 5A
1,513,921,791
key
0x5A3C9F17
17 9F 3C 5A
1,513,922,327
The bytes E8 03 00 00 are gone. A search for 1000 returns no address that belongs to the gold.Now the player spends 150 gold. The wrapper picks a new key, for example 0x2B71C4D9:
Field
Hexadecimal
Bytes in memory
As a decimal number
encrypted
0x2B71C78B
8B C7 71 2B
728,876,939
key
0x2B71C4D9
D9 C4 71 2B
728,876,249
The player sees 850 on the screen. Memory went from about 1.5 billion to about 729 million. A search for 850 finds nothing. A search for "value went down" is not reliable either, because the stored number jumps in a random direction on every write. Here it happened to go down. Next time it may go up.
Takeaway: The scan needs a known number at a stable address. XOR with a fresh key takes away the known number.
What does it cost?
Not much. The protected value needs two int fields instead of one.
Version
Fields
Size per value
Plain int
value
4 bytes
ProtectedInt
encrypted, key
8 bytes
Even 10,000 protected values are 80 KB instead of 40 KB. Every read costs one extra XOR, and every write costs one XOR plus a new random number. That is fine for gold, health, or a score. I would not wrap values that change thousands of times per frame in a tight loop, such as particle positions. Those are not what cheaters go after anyway.
What XOR does not stop
XOR has limits, and I do not want to oversell it. A key that sits right next to the value is not strong encryption. It hides the value from a scan, and that is all.A player who knows how to read your code can find the wrapper, see the XOR, and do the same math by hand. A search for "value changed" can still narrow down the address over many rounds. And the wrapper does nothing against other cheats, such as speed hacks or patched game code.But it removes the simple cheat that every player can do without any skill: search for the number, change the number.There is one more step that makes the wrapper much better, and that is detection. Keep a third field with the plain value as a decoy. The game never trusts it. It only compares it:
publicint Value
{get{int real = encrypted ^ key;if(decoy != real){// Someone changed the decoy from outside the game. CheatDetected?.Invoke();}return real;}}
The decoy needs one more line in the constructor (decoy = value;) and a public static event Action CheatDetected; on the struct. It costs 4 more bytes, so 12 bytes per value.Now Cheat Engine finds 1000 again, but it finds the decoy. The player changes it, the real gold does not move, and your game knows that someone edited memory. What you do with that is up to you. I would not ban on the first hit. Log it, reset the value, or flag the save file.For anything that touches other players or real money, the answer is still the server. Keep the value there and treat the client as a display.
Conclusion
Cheat Engine works because Windows lets one program edit another, and because a plain int in memory is the same number the player sees.So do not rely on private or on properties, and do not keep important values as plain numbers. Encrypt them with a fresh key on every write. Add a decoy and react when it changes. And keep multiplayer values on the server.The wrapper above covers one type. A real game also needs float, double, bool, long, string, and vectors, plus Inspector support and much more. If you do not want to write and test all of that yourself, have a look at GuardingPearSoftware Anti-Cheat. It has protected types for these that you use in place of the normal ones. They work with the same XOR and decoy idea, and a detector reports the edit.
00 views
00 shares
Discussion about this post
No comments yet. Be the first to start the discussion.