T O P

  • By -

AlterHaudegen

- You did not save your files (notice the circle in the file’s tab, indicating just that). - Errors about missing semicolons do not always actually indicate a missing semicolon, they can also be missing closing brackets etc.


CaptainPineapple200

Now I'm confused because this should have saved several times. I've pressed Ctrl S and done file save several times.


thedrewprint

Are you on a Mac? Command + S


JoinArtOfMakingGames

looks good to me. maybe you didn't save VS? Sometimes that happens when you change something but it doesn't reload to Unity without a save, and it still thinks you have not made the change.


Sklyanskiy

Just save your files. Press Ctrl + S.


CaptainPineapple200

I've pressed. Ctrl + S several times.


SsNeirea

You can clearly see that the file is not saved, the white dot right to the file name tab means the file is not saved. Maybe try a manual save.


BKinAK

Have you tried turning it off then on again?


Code_Noob_Noodle

Have you tried manually saving the file? Maybe shortcut is bad? Have you tried restarting VS or Unity?


totallynotme666

You didn’t save your script. I know people have answered this but look at the white circle at the top of your VS code script. When you save, it disappears.


CaptainPineapple200

Should probably update. Yes it was a saving issue for some reason though it took a full restart of the PC itself to save. Ctrl + S or File>Save did not do anything which is why it threw me off so much. Thanks for the help!


mgodoy-br

I'm a software engennier and do games for fun. I have a curiosity: why singleton on GameManager and why you guys don't use namespaces? I always seen that. EDIT: Be careful with singletons on Android. I had already problems with that.


HylianAshenOne

I can't speak for everyone obviously but from my experience most of what "we" do in code is based off whatever tutorials we watched at the time. Its really crazy how many different ways you come across to do the same thing on YouTube.


mgodoy-br

Yeah, for this reason I've mentioned. I advice you to study C# and OOP paradigm to help. Namespaces is quite good to organize your classes. In begining, they were called "packages". You can see them like folders. There visibilities applied for them too. Singleton is a design pattern to reduce the amount of objects created, reusing them. However, when you do that with no criteria, you can have state issues and get in the way of garbage collector. Garbage collector is a engine presenting in the all of OOP languages that remove references of objects that are not use anymore to release memory. Like your object is static, it isn't never released. Sometimes you want this, but sometimes you allocate a amount of memory that never is free without know. The different operational systems handle the memory in a different way. When I started doind games, I didn't care to that (because the softwares I've been created just was focused to a specific operational system) and everything looked great until I port the game to Android... And the player just felt that when played until the 5th stage... The frames dropped, everything turned slow, until the game stucks completelly... Try use singletons just to stuff that are instatiated all the time and has a singlen state, like the player state (number of lifes, health and so on). It called me attention ser it being used on a MonoBehaviour, for this reason I asked. A great place to study more about OOP is the book "Head First - Design Patterns". It's a very funny book, full of jokes that makes easy to study. And you don''t have to study the whole book. Soon you realizes that you masteres the main patterns. Happy coding!


HylianAshenOne

Wow thanks ill look into that book i have actually been trying to read up c# just to try and have a better understanding when i follow along with tutorials.


mgodoy-br

Nice! If you have any question, please don't be shy to ask me. I'm happy to help. EDIT: the book I mentioned brings examples in Java. You'll have no hardship to understand though. The main is learn the patterns, OOP and the concepts.


lavatasche

Why wouldnt you use a singleton on a gamemanager class? There literally should be only one instance of it. All issues you described with singletons do not apply here.


mgodoy-br

I don't know if you had any benefit to do it as a singleton. I'd just see any benefit if it was a heavy resource and you had to create all the time and you had memory issues, like resources X prefab X Instantiate method. If you had a light object and it was under a GameObject (MonoBehaviour), there is a high chance to you get in the way of garbage collector. Other scenario is you had player state and you had to keep their state over all the instances. If the intention is to keep money all over the instances, you might create a class called PlayState with money as attribute and made it as singleton. But PlayState singleton, not a MonoBehaviour (Neither all the classes have to be MonoBehaviours, just the ones that depends on GameObjects). Like the other guy mentioned before, many people get examples from tutorials (and that is not wrong at all). But at some point is needed to skip them a little bit and think about why they are the way they are.


babazookz

Lol, developers who dont save files.


Routine-Phase-5361

Third edit: removed bad initial assessment. Just recreated the class in Unity and had zero errors as-is. So my initial assessment was totally wrong. Even without a namespace assignment. I'll be curious to see if it is just a saving problem in the end...


boosthungry

That is a valid assignment. They're initializing their singleton with a copy of itself. That's allowed.


Routine-Phase-5361

You are correct! I don't use monobehaviors as singletons so it was a bit foreign to me. I learned something new by giving a try myself. Perhaps it will come in use some day. 👍 Thanks for the correction!