Hello! If you're looking for some snarkiness, self-deprecating humor, and what NOT to do when creating your first Unity project, you've come to the right place.
Today's lesson: How to spend 3 hours adding a single component to a GameObject. Spoiler alert: I did it wrong. So, so wrong.
Morning me, full of hope and coffee: "Today I'll implement my tilemap farming system! Should take an hour, maybe two. I already have all the scripts!"
Narrator: She did not, in fact, have working scripts.
I right-clicked on my GameObject, selected Add Component, typed "Farming"... and nothing.
Nothing showed up.
My component didn't exist.
Unity had eaten it.
Now, a SMART developer would immediately check the console for errors. But did I? No. Instead, I did these things in this EXACT order:
Because obviously Unity just forgot my scripts existed. A quick restart would jog its memory, right?
Result: Still broken. But now I had to wait for Unity to reimport everything.
Clearly the file was corrupted. Delete it, create a new one, copy-paste the code back in.
Result: Still broken. Now with bonus trust issues.
Found 47 different solutions ranging from "clear your cache" to "Mercury must be in retrograde."
Result: Wasted 30 minutes. Mercury's position did not affect my code.
Made a simple "TestComponent" with literally nothing in it to see if ANY new components would show up.
csharp
public class TestComponent : MonoBehaviour { // This is fine. Everything is fine. }
Result: TestComponent ALSO didn't show up. Starting to question reality.
Turns out Unity DOES have a Safe Mode. It shows up with a banner at the top when you have compilation errors on startup. Was I in it? No. Did I know it existed? Also no. Did I spend 10 minutes looking for a "Safe Mode" toggle in preferences? Yes.
Result: I wasn't in Safe Mode because my errors happened AFTER Unity started. Safe Mode is for when you break things so badly Unity can't even open properly. I hadn't achieved that level of destruction. Yet.
And there they were. 12 beautiful red errors. Just sitting there. Waiting. Judging.
They'd been there THE WHOLE TIME.
csharp
Vector2Int[] tilePattern = GetPattern(); if (someCondition) { Vector2Int[] tilePattern = GetPattern(); // THE SAME NAME. WHY DID I DO THIS. }
What NOT to do: Use the same variable name in nested scopes and expect C# to read your mind about which one you meant.
What to actually do: Use different names. Like tilePattern
and layerPattern
. Revolutionary, I know.
csharp
foreach (var thing in myList.ToList()) // Unity: "What's ToList()?"
Me: "It's a LINQ method! Everyone knows that!" Unity: "Did you import System.Linq?" Me: "..." Unity: "..." Me: "No."
What NOT to do: Assume Unity will magically know what libraries you want to use.
What to actually do:
csharp
using System.Linq; // At the top. Like a normal person.
csharp
using MysticValley.Magic; // Trying to import SpellTargeting // Meanwhile, in SpellTargeting.cs: public class SpellTargeting : MonoBehaviour // NO NAMESPACE. IT'S GLOBAL.
I was importing a namespace that didn't contain the class I wanted. It's like looking for your keys in the refrigerator. They're not there. They were never there. Stop looking there.
What NOT to do: Guess where classes live based on their file location.
What to actually do: Actually CHECK if the class has a namespace before trying to import it.
csharp
if (SaveLoadUI.isAutoSave) // This field... doesn't exist
The compiler, very patiently: "What is isAutoSave?" Me: "It's a bool!" Compiler: "Where?" Me: "In the... somewhere!" Compiler: "..."
What NOT to do: Reference fields you haven't declared and hope they'll spontaneously generate.
What to actually do: Declare your variables. All of them. Before using them. Wild concept.
Oh, and half of these problems? They're because I upgraded to Unity 6, which is apparently the strict parent of Unity versions.
Unity 5/2020: "FindObjectOfType? Sure, I know what you mean!" Unity 6: "It's FindFirstObjectByType now. Be specific. Use proper grammar. Sit up straight."
Unity 2020: "System.Linq? Yeah, it's probably imported somewhere." Unity 6: "EXPLICITLY IMPORT EVERYTHING OR PERISH."
Not after restarting Unity. Not after reimporting. Not after sacrificing a USB cable to the coding gods. FIRST.
One error in one script breaks EVERYTHING. Your perfect scripts? Broken. Your working components? Gone. Your will to live? Questionable.
It wants explicit imports, proper method names, and correctly scoped variables. It's not here to be your friend.
3 hours of troubleshooting. 5 minutes of actual fixing. It's always like this.
csharp
// Fixed variable scoping Vector2Int[] tilePattern = GetPattern(); if (layerManager != null) { Vector2Int[] layerPattern = GetPattern(); // DIFFERENT NAME! } // Added the import using System.Linq; // At the top where it belongs // Removed the fake namespace // NOT using MysticValley.Magic because SpellTargeting ISN'T THERE // Added the missing field private bool isAutoSave = false; // It exists now!
After fixing all 12 errors (which were really just 4 errors in different outfits), my FarmingLayerManager component finally showed up.
I added it to my GameObject.
It worked perfectly.
I stared at it for a solid minute, wondering why I do this to myself.
Oh, here's the best part that I haven't mentioned yet: These components? They WORKED two weeks ago. They were fine. Perfectly functional. Adding themselves to GameObjects like good little components should.
But then I decided to be "professional" and "clean up my code." I went on a purge of things I "didn't need" and "leftover code" that was "cluttering the project."
Turns out when you delete "unnecessary" using statements and "redundant" field declarations, they're not actually unnecessary or redundant. Who knew?
I am literally the bane of my own existence. I broke my own working code while trying to make it "cleaner." It's like vacuuming your house and accidentally sucking up your car keys, your wallet, and your will to live.
Past me: "I'll just remove these extra using statements, they're not doing anything!" Present me: "THEY WERE DOING EVERYTHING YOU ABSOLUTE WALNUT."
Actually implementing the farming system. You know, the thing I was supposed to do today before I decided to speedrun every possible wrong solution first.
But hey, at least now you know what NOT to do:
You're welcome.
P.S. - If your component isn't showing up, check the console. And if it was working two weeks ago before you decided to "improve" things? Check what you deleted. It's probably important. Trust me, I'm an expert at breaking my own code.
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.