Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Day 21: A Masterclass in What NOT to Do (Featuring 12 Errors and My Dying Soul)

A Masterclass in What NOT to Do (Featuring 12 Errors and My Dying Soul)

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.

What I Thought Would Happen

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.      

What Actually Happened

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:

The List of Things NOT to Do (That I Absolutely Did)

1. Restart Unity

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.

2. Delete and Reimport the Script

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.

3. Google "Unity component not showing up"

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.

4. Create a Test Script

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.

5. Check if I'm in Safe Mode

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.

6. Finally Check the Console

And there they were. 12 beautiful red errors. Just sitting there. Waiting. Judging.

They'd been there THE WHOLE TIME.

The Errors That Broke Me

Error #1: The "I Used the Same Variable Name Twice Like a Genius"


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.

Error #2: The "I Forgot How Imports Work"


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.

Error #3: The "I Invented a Namespace That Doesn't Exist"


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.

Error #4: The "I Used a Variable That Doesn't Exist"


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.

The Unity 6 Plot Twist Nobody Asked For

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."

The Emotional Stages of Debugging

  1. Denial: "The component is there, Unity just can't see it."
  2. Anger: "WHY WON'T YOU SHOW UP?!"
  3. Bargaining: "If I restart Unity ONE more time..."
  4. Depression: "I'm not cut out for game development."
  5. Acceptance: "I should check the console."

What I Actually Learned (Besides Humility)

Always. Check. The. Console. FIRST.

Not after restarting Unity. Not after reimporting. Not after sacrificing a USB cable to the coding gods. FIRST.

Compilation Errors Are Contagious

One error in one script breaks EVERYTHING. Your perfect scripts? Broken. Your working components? Gone. Your will to live? Questionable.

Unity 6 Doesn't Care About Your Feelings

It wants explicit imports, proper method names, and correctly scoped variables. It's not here to be your friend.

The Fix Is Usually Stupidly Simple

3 hours of troubleshooting. 5 minutes of actual fixing. It's always like this.

The Working Code (After My Dignity Died)


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!

The Aftermath

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.

The Plot Twist That Makes This Even Worse

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."

Tomorrow's Plan

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:

  • DON'T restart Unity before checking the console
  • DON'T assume components are missing when it's probably compilation errors
  • DON'T forget to import System.Linq
  • DON'T use the same variable name twice in nested scopes
  • DON'T reference variables that don't exist
  • DON'T trust Unity to guess what you mean
  • DON'T upgrade to Unity 6 without tissues nearby
  • DON'T "clean up" working code at 2 AM
  • DON'T delete "unnecessary" imports without checking what they do
  • DON'T be your own worst enemy (too late for me)

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.

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.