how do you keep your application maintainable? it's almost impossible

how to move an asset without breaking everything?

I am learning unity and seems to me that it’s big pile of spaghetti code that break each time I move or rename anything. I can’t restructure my work, I can’t easily add feature. while unity has all the information about an asset when it’s moved or renamed, it does zero help to update the linked asset after a move.

if I move/rename a sprite, it looses it’s “texture type” and I need to reapply the same type that unity already knew about it.
if I move/rename anything, all references are gone.
if I rename a script, it won’t work anymore unless I fix it inside VS
if I rename an animation controller it breaks and I need to recreate it.

the Game.Find is depending on pure string and if I want to change the component name, I need to go and figure out where it’s used.

does unity expect to never change the folder structure or an asset name?

to be frank it’s quite ugly and unmaintainable to write code and create application and add new feature in this way. I searched but couldn’t find any asset or package that helps about this and most of google result is generic topic about how to move files with scripting api and nothing about usability.

how do you guys move items without a need to reassigning any reference to that? how do you find game object without hard-coding it’s name in your script?

If you move o rename stuff outside Unity, chances thing will break. Unity relies on metafiles and unique ids of file assets. If you move assets in explorer for example, Unity has no way to track them correctly. Specially if you forged, or delete meta files.

So if you want to move stuff around, you need to do it inside Unity editor.
Then meta files are reassigned correctly.

However, if you project breaks, just because you moved something, chances are, that your architectural design has major flaw.

Some assets are bad, as they do not work, if they are located in wrong folder location. You should avoid them.

You CAN move thigns around, but you have to do it inside unity, or you have to do it with a file manager that shows hidden files. Unity uses companion *.meta files for pretty much everything. Their move/rename is handled by the unity editor when done through unity editor, but if you’re moving something outside of editor, taking care of them is your job.

I just never move or rename anything from the asset store. I find that it’s just easier to keep assets in their original location, especially when you go to install a newer version of that asset. I create a folder in the assets folder called “zzz_main” (so it’s always on the bottom) and put all of my stuff in there. Then I just leave everything alone that’s not inside that folder.

2 Likes

Just to touch on this one point:

GameObject.Find should ideally be reserved for last-resort niche cases where you don’t have any better way to get a reference to a GameObject, and I’d argue there’s always a better way.

Dragging/dropping the reference from the inspector or getting the reference from some MonoBehaviour component should be two of the most common ways to go about it.

I’ve yet to ever find a reason to actually use GameObject.Find over other methods.

3 Likes

thanks for all the answer, but it’s not what I’m experiencing.

I’m using unity 2021.2.7f1.4128 and as I said things won’t get resolved automatically. I am doing all the changes inside the unity, so I expect unity do the rest, but that’s not what I’m seeing in here.

I record some gif to be more explicit what I’m experiencing.

moving a script make it missing reference:
7775016--980493--move a script become missing referrence.gif

move prefab cause missing reference:
7775016--980496--move prefab cause missing reference .gif

move sprite break texture type:
7775016--980499--move sprite break sprites .gif

rename prefab breaks the references:
7775016--980502--rename a prefab break the reference .gif

rename animation controller breaks the animation:
7775016--980505--rename anim ctrl break the animation.gif

so as you can see it’s not about meta files. since you guys mentioning different behavior it should be bug and unfortunately it’s very annoying for me. anyone from unity team to report these?

Report it as a bug, if its already reported it will get marked as duplicate. Better to just report rather than asking if anyone has reported it, this is not a support forum and so unlikely to hear if people have reported this specific issue or not.

Definitely a bug. It looks like for some reason Unity is not moving the meta files when it moves the asset files.

Also check for weird conflicts with third party virus protection software.

Whilst it may be a bug, I suspect it’s more likely to be something wrong with your project or system, or both.

Obvious causes to check would be anti-virus software, cloud saving etc, something that might be messing with the files or meta files. One other thing that comes to mind is whether the project is from a back up like a zip file that has been downloaded from the internet, as on Windows the zip will be marked as potentially unsafe. Unfortunately when you unzip it every file within the zip will also be marked. The only way to remove it is to go to file properties and click the ‘unlock’ button. If that’s the case then you’ll better of unlocking the zip before unzipping.

Before doing the next steps you MUST make a back up of your entire project including library, just in case. I’d simply the zip up the entire project folder.

next I would check the project settings > editor and make sure meta files are set to visible, and set files to be saved as ‘force text’. See if that makes any difference. If not then delete the library folder ( you made a back up first right.) then re-load the project. If for some reason you have no meta files rebuilding the library will completely break the project.

Other than that I’m not sure. If you are willing and the project isn’t to big you could zip it up and share it to see if any can check it. That might reveal an issue with the project or point more to a problem with your system. If you aren’t willing to do that because you don’t want to share it, then definitely report it as a bug and give Unity the project as they might find the issue and have a level of trust random people online wouldn’t.

1 Like

Try the things @Noisecrime mentioned. The behavior you are seeing is definitely not correct. It is definitely related to the .meta files in some way, note the warnings on the status bar. Meta files contain references and id for the assetdatabase. Broken links/refs are the kinda thing you see when metas get deleted or corrupt.

Do you have anything outside the norm set up, like sym/hard links for the directories, or working from a network directory? I suspect it isn’t a Unity bug, as this would massive breaker for everyone. If you were on a Mac, it could be a permissions problem, dunno if there is a Win equivalent.

Also, as a random thought, one of your images shows a performance error related to preview scenes. I have had in the past a problem with heavy editor stuff running and interfering with normal operation. (it was bug in our code that made the editor tool run all the time). In addition to the trouble shooting mentioned earlier, you might also try creating a new, empty project and just a couple of assets and a test script and see if that is still a problem in a new project.

you guys are right!
I’ve created another project from scratch in the same parent folder and everything was fine, so somehow that project went into the breaking state, not sure what. so I tried to clean it and notice there are some folders that I can’t delete them with unity. when I delete them and their meta files then I could see that everything works as it should

thanks everyone for help