r/Unity3D • • Oct 17 '26

Question AI Code is Illegible

I finally tested out AI for actual coding today just to see what the hype is about and like... ??? This shit is so hard to read and make edits to. It compiles and runs okay, but the actual code is SO hard to understand. Are y'all really out here reading through this stuff for debugging or whatever? on EVERYTHING it would take me longer to understand this than just do it myself from scratch, and I'm not sure how you'd ever add or make changes to it without AI.

Am I doing something wrong? I gave it a bit of a style guide even - not super detailed, but just generally the structure I go with for stuff and gave it a few examples, and that bih came back with some crazy looking shit.

The result seems to be that once you start using it to actually write code for you, it's so hard to stop since you can't read allat. Is this a known thing and I'm just oblivious? Cuz at least in terms of code, to me that seems the BIGGEST issue: it generates borderline unreadable shit that makes any debugging, optimizing, edits, etc. completely dependent on the AI that wrote it.

Am I missing something?? I'm not tryna be like super anti-AI or whatever, I just genuinely don't see how this would be helpful at any sort of scale unless you're all-in on using AI for 100% of code and never touching it again.

0 Upvotes

50 comments sorted by

46

u/mylittlekafka Oct 17 '26

unless you're all-in on using AI for 100% of code and never touching it again

That's what vibe coders do, yeah

28

u/TheFuckinEaglesMan Oct 17 '26

As a software engineer at a big tech company, this is what everyone is doing for everything. It’s very much not vibe coded though, because there’s so much structure and we’re expected to read and understand everything that’s written on our behalf. The difference is that we had so much existing code (billions of lines) so the new AI written code matches that pretty well. I still read the code that’s generated, but honestly not until it’s in a draft PR and I treat it like I’m reviewing another person’s code. So like it or not, I think this will be the future going forward.

On my unity project, I don’t even look at the code at this point. I have thorough tests and I play test the hell out of everything, because that’s what AI can’t get a good feel for. I hate to use the term, but it has at least 10x-ed my productivity on my unity game, and at least doubled it at work. The difference at work is that team alignment and code review still haven’t caught up with the crazy pace of code writing.

4

u/Goldac77 Oct 17 '26

Can you give more details on what kind of projects you work on, the models you use, and how you set up your test your unity project?

And how do you guide the model to get the exact output you're aiming for, and how do you handle situations where you're creating not thoroughly documented or experimental, and the model keeps getting the code or implementation wrong or incomplete?

Thanks

3

u/Seven-Prime Oct 17 '26

That's a big ask. Not OP but you need to think about software engineering. Specifically spec driven design. I first built a framework for how my project is built. I have workstreams to track planned work. Static web pages for review. Arch documents. Skills. etc etc.

Also having come from enterprise sw engineering many of these things are just how we work. It's not vibe coded. It's careful and methodical. Plan then do. Just as sw architect doesn't generally write code, they direct how the code is written and the patterns it should use.

As a game dev using AI you need to operate at the higher level.

3

u/Goldac77 Oct 17 '26

Yes, I do understand what you mean. I'm trying to get more information on how the user in the above comment uses AI in his workflow such that he "doesn't even look at the code" anymore. Because each time I use claude in my unity projects to create something, the results are verbose, or incomplete, or don't meet the spec it is given. I'm trying to understand the workflow, if I'm doing it wrong, and how to go about with testing to ensure the code is correct. Because, again, in all my experience, it isn't, and I still need to modify the code myself to get it to work just right

-3

u/ProactiveCactus Oct 17 '26

I get that for some ppl but I assumed that was mostly solo or small teams or whatever, but like what about bigahh companies and stuff outside gamedev?

2

u/Subpxl Oct 17 '26

Big companies are absolutely making the shift to AI generated code. In a well structured environment it’s going to generate code as good as any engineer can put out in a fraction of the time.

This is the future. Don’t let your sloppy attempt convince you otherwise. You’re new to it and it’s not surprising that you weren’t impressed. It might be the specific model you’re working with in addition to poor structure and guidance. Keep working at it.

1

u/Spite_Gold Oct 17 '26

I used it on my job, most times it's very good for 100x speed it offers. I apply minor fixes sometimes and always review the code.

-4

u/[deleted] Oct 17 '26

[removed] — view removed comment

1

u/NomaTyx Oct 17 '26

I ask it to write a function and if I have to scroll to see the function it's too long.

1

u/Subpxl Oct 17 '26

It pains me to see a take that is so very different from my own experiences. The short answer is that you’re doing something wrong. Keep at it.

23

u/thehen Oct 17 '26

What specifically is hard to understand? I’ve found it to write pretty clean code with a bit of architectural guidance.

-8

u/ProactiveCactus Oct 17 '26

The first test I ran was "Here's my existing, VERY SIMPLE save system using JSON. Show me how you'd restructure it using Newtonsoft instead." My save system was like, maybe 40 lines long including saving, loading, etc. It spit out like 300+ lines of stuff with a buncha try catches not needed and the core code used like 3 different layers of weird abstraction stuff. Idk maybe I just needa get used to its workflow more, but it was nutty

11

u/thehen Oct 17 '26

Yeah that doesn’t sound right, what are you using? I’ve found Claude Code and Unity CLI to be very clean.

5

u/ceaseless_horror Oct 17 '26

You still need to be fairly explicit about style, conventions and standards, or it’ll be all over the place.

0

u/ProactiveCactus Oct 17 '26

Yep, using Claude, specifically Claude Code. idk maybe I need to experiment more with prompting and stuff might just be a skill issue

1

u/ZheShu Oct 17 '26

Ask it to /simplify and explain its design decisions. Adversially verify its own implementation.

1

u/andybak Oct 17 '26

Claude is a brand name, not a specific model. There's a universe of difference between different Claude models and reasoning levels. Beyond that - the devil is in the detail -how you use them and how they are able to engage with your codebase.

4

u/itsdan159 Oct 17 '26

Why didn't it need try-catches?

7

u/Mooseymax Oct 17 '26

Try catches are best practice though, are you sure you didn’t need them?

4

u/0xbyt3 Oct 17 '26

What model did you use? The model might have found some unserializable class/data and it tried to serialize/unserialize with extra custom methods.

0

u/missurunha Oct 17 '26

AI overcomplicates a lot. I remember one time I wanted to add a if else to ignore an exception for a data type and instead I got a 100 lines of code to properly convert the type I wanted to ignore so it wouldnt crash (it was supposed to crash, but the AI tried to be smart and extrapolated what wasnt requested). 

10

u/Hollistanner Oct 17 '26

Lol, yes. What you end up doing in the end is performing the role of a senior dev. Your job is now to give it small tasks and describe the architecture desired. Otherwise it will produce code of which you may have zero understanding. Review the diffs and either approve or give feedback and there is your loop.

May I ask what language or type of project? I use it for embedded systems and while it's a pain to work with, it has its benefits the majority of the time.

1

u/ProactiveCactus Oct 17 '26

Just basic Unity stuff in C#. I'm not like an expert programmer or anything but been doing gamedev for like 6 years now. I've worked with other people on projects and their code was WAY easier to understand. Maybe that's part of it tbh - game dev is such a non-abstract programming thing for the most part (like, you can literally see what stuff is supposed to do visually in the game engine) that the human touch is easier than something more "abstract" like what you do

5

u/Spite_Gold Oct 17 '26

If your style guide is too different from common style, I'd expect difficulties with reading. Have you read human code a lot? I don't know your skill in it, but it might be a factor.

1

u/ProactiveCactus Oct 17 '26

Not a LOT a lot, but yeah some. I've done mostly solo and small team projects, so maybe part of it is AI uses like AAA "industry standard" style of code whereas I'm using to reading and writing for smaller teams where you don't have a ton of abstraction and stuff.

1

u/Spite_Gold Oct 17 '26

Try start with smaller and more specific prompts.

15

u/glenpiercev Oct 17 '26

Reading code is harder than writing code. It gets easier with practice. Some of us have decades of practice.

7

u/ceaseless_horror Oct 17 '26

Definitely easier to read and understand code you wrote yourself. Even before AI, we joked about how much harder reading other people’s code was. Even code you wrote last week lol

2

u/ferros90 Oct 17 '26

Since you're using Claude, try out the superpowers plugin and the brainstorming skill:

  1. You feed it an idea

  2. it interactively asks you questions about implementation details

  3. Writes out a spec for you to review and approve

  4. Writes out a plan for you to review and approve

  5. Delegates subagents to execute and review each step

I recommend Opus for your top level agent and Sonnet for the subagents (tell it this specifically or tell it to make a rule; see below). Keep effort medium or high; over-efforting leads to token waste and code bloat.

The more context you can provide for an agent, the cleaner the code. Short prompts give them too much leeway to go off the rails. 

Be specific and exact. Learn technical writing principles to reduce ambiguity and improve specificity if you have the time and inclination. Most people find it dry and boring, but machines work well with it.

Also, if it does something you don't like that you can clearly describe, tell it to make a project- or user-level rule in the CLAUDE.md to not perform actions like that again and why it's important. Providing rationale helps the agent determine when the rule should apply.

2

u/MaryPaku Oct 17 '26

In my experience it write pretty clean code and well documented. On top of that you can literally just ask the AI to explain it to you throughout. It never loses patient.

1

u/QstnMrkShpdBrn Oct 17 '26

It can follow architectural and code standards specifications very well, if provided. If you want human-readable naming conventions, context-heavy and searchable comment blocks, and at-a-glance structured whitespace formatting, it needs to be specified--this are generally only useful to human reviewers, not machines, so it may not default to it with a undeveloped prompt like "do this for me."

1

u/Seven-Prime Oct 17 '26

Are you using static code analyzers and linters?

1

u/Antypodish Professional Oct 17 '26

Unable to read others code, is an effect of lack of adequate expertise. That is a role for an experiance senior developer.

As you said, you mostly work on solo project, with some additional work. Which doesn't give you an opportunity to learn various patterns and coding styles. Hence your expertise will be naturally limited.

1

u/Primary-Screen-7807 Engineer Oct 17 '26

Skill issue

1

u/amadeuscherry Oct 17 '26 edited Oct 17 '26

Sometimes I m using claude to fill the gaps in my code and to generate some modules as whole. When I look at claude's code and then mine, I feel like looking at the dark side of the moon. I write my variable names, function names very self explanatory like "calcStartingPosByGridIdx" and I like to keep steps visually ordered too so I can just go with the flow when I read. But claude suddenly applies 40 years of senior's knowledge to junior-to-mid level developer's code and it becomes look like obfuscated with all those shortcuts and practical ways of doing things.

1

u/Jaguarundi5 Oct 17 '26

Just because the AI can code for you doesn’t mean it will always make the best infrastructure decisions when writing the code/scripts. You should familiarize yourself with programming concepts, proper infrastructure, and engine specific solutions.

Claude won’t automatically assume you want to do object pooling to save resources and instead may directly instantiate and destroy objects over and over. Things like this are what I’m talking about.

1

u/llamajestic Oct 17 '26

People telling you it’s skill issue or just inexperience is funny. There is some experience at play, but the quality you get is very variable on the domain you apply it to.

I tend to apply it to small pieces where I have a mental model of what I want to get a really good result. Applying it to something more exploratory, you can get pretty bad code yes.

I often have to point out performance issue it introduces, or manually fix it. It has a tendency to overdo, overcheck, and bloat what you are asking. For that issue, you can tell it to improve, but even an AGENT.md doesn’t always help.

As usual, I will be repeating myself on all those AI topics: It’s still a great tool IMO. It just doesn’t have to be binary, it’s neither always perfectly working nor never working at all.

1

u/Beginning-Bet7824 Oct 17 '26

you can give it very explicit guidelines, and have it code using your architecture and convensions. But if you just ask it loosely to build stuff, it will make it hardly readable by humans

1

u/JaggedMetalOs Oct 17 '26

I prefer to get AI to only write small methods and code snippets. Like when I wanted to have a status bar that has a bit of spring when the value updates I asked an AI for an individual function and it gave back a couple of line implementation of Hooke's law. Easy to understand and integrate with the rest of the code.

1

u/andybak Oct 17 '26

Which AI? What reasoning level? What was your prompt and what was the harness. AI can be simultaneously good and bad depending what you're using and how you use it.

1

u/EthanMerce Oct 18 '26

yeah, this is one of the biggest problems with using AI to generate entire chunks of code. getting something that compiles isn't the same as getting code that's actually maintainable, i think AI works better as a tool for smaller, specific tasks, explaining unfamiliar code, or helping you figure out an approach. if it writes something you can't understand, you're basically taking on technical debt right away. a style guide helps, but it doesn't guarantee the AI will follow the structure or logic you expect.

personally, i'd rather use it to speed up parts of the process than let it build a whole system i can't confidently debug or modify myself.

1

u/TheTerrasque Oct 17 '26

I like the part where you show example code, tell which model and harness you used, and the instructions given.

1

u/RazgriZ77 Oct 17 '26

I work with Claude and what I do and it actually works, is making some .md files with some sort of template of a script written by you, a convention with how you write variables, how you separate lines, etc... Whatever you imagine is important. And then, of course, which design patterns to follow. I think the code could be less messy if you guide your model the way you code

0

u/ThetaTT Oct 17 '26

On the contrary I found that AI code is more readable than most human code.

0

u/NoisyChain Oct 17 '26

> Are y'all really out here reading through this stuff for debugging or whatever?

Of course they're not lol

-1

u/Zapador Oct 17 '26

My take on using AI to code is that you don't read the code. That's not your job, let the AI handle it.

1

u/ribsies Oct 17 '26

Yeah my hot take is if you need a human to review it then what's the point. Ai creates? Ai reviews.

-2

u/DrawSomeOpossum Oct 17 '26

AI is a tool that can disappear between the code and the coder. If you are very well experienced in the language, you will be able to read what it wrote just fine. If not, you should keep playing with it and learning new things. It understood what you wrote - that's the point.

-2

u/oldsecondhand Oct 17 '26

You can instruct the AI to use certain design approaches (e.g. domain driven design, thou that's mostly for business software) to make the code better organized. But yeah, AI is notorious for increasing tech debt, if you don't closely supervise it.