The question is answered
Scripted GameObjects vs Prefabs
I have read that coding with GameObjects names as strings can be bad, due to the ease of renaming. Should I build my GameObjects in code or keep using prefabs? Ideally these GameObjects designs shouldn't change, but I might want to change the names at some point in the future.
Thank you.
Do you have any example code so it is easier to understand what you intend to do?
I'm not at my computer right now, but I will try to explain it better.
With a prefab you can use a Resources.Load (path/name). However if I go to the prefab in the suite I can rename it, which breaks all the Resources.Load ().
An alternative is to make a c# class ins$$anonymous$$d of a prefab, which sets all the components fields in its start method. If I change the gameObjects name field it won't break the code. Likewise if I change the class name, it will ask if I want to refactor my project. $$anonymous$$eaning it still wouldn't break my code.
Which would you suggest?
if you are a fan of writing configuration code for hours, basically replacing the fast and efficient possibilities one have with the inspector, than it's the way to go. But if you ask me I'd rather have a bad name three times a project than program$$anonymous$$g configurations.
You could also just have one class handling the path finding so the strings exist only once. If you must, implement a debug function that checks all gameobjects for their existence in the resources folder. just a side note, animations are also string bound and probably the bigger problem.
Oh, I forgot I could just make a file with the prefab names. Thank you.
Follow this Question
Related Questions
GameObject changes to None in inspector after pressing Play 0 Answers
How to attach a GameObject to a Prefab that has many scripts attached? 0 Answers
Why does GameObject.FindWithTag() get a wrong instance? 2 Answers
How can I change the root game object of a prefab in the editor? 1 Answer
Quiz Game Management 0 Answers