#IDE Configuration
1 messages · Page 1 of 1 (latest)
So, you're using Visual Studio Code, which is entirely different from Visual Studio, even if the names don't differ that much
If you have a decent computer I would advise dropping VS Code and installing Visual Studio 2022
Alr
Whats the difference
It's heavier, but it installs 100 times faster. No package and extensions needed
It's fully built-in
I see
So takes more space but got everything built in
lemme uninstall this one then
getting 2022 rn
Community, the other two are for professionals and paid
I wish i could lie and say im a professional lol
I see
If you want to pay $2500 per year, sure
Perfect way to spend my money
Just let me know when the install is complete and when it prompts you to install "workloads"
Installer is (yet) another application that you can run to manage what workloads are installed on your system
Game Dev With Unity is the one you need, and since you already have Unity installed, on the right pane you'll have to de-select "Unity Hub"
Yes
Quick question
Unrelated but u can just choose to skip it if you want
I do code in python some times using visual studio, do i select the python option too or do i just skip it if i already have python installed?
U can just skip this question if u want its completly unrelated
You can select the workload so VS supports editing Python scripts, but not sure if it'll install other versions of Python with it
Alr
I got the latest one so hopefully if it tries to install another one on top of it it will just replace the files
Alr installing!
Or it'll install along the other Python versions, and when running from VS it'll prompt you which version you want to run it with
that might be the case
Once the install completes you can close the installer, and switch back to Unity, to finish the config on that side
soon done
Alr
Its done
Lemme just sign in
I'll probably get used to the start menu
Alr then time for the unity side
So, in Unity, Edit > Preferences > External Tools
In the dropdown select VS22 Community, and hit the Regenerate Project Files button
And that's all there is to it
Hmm, it should be there
Maybe the whole computer, so VS things go in the PATH
O
alr
wait
before i was gonna do that
i tried opening a script
to see if i would get the menuy where i can choose
but it opened using Visual Studio 2022
Does it have to be selected in the external tools
Yeah, here it failed to load
alr
"Misc files" and uncolored Unity types are hints
O
alr
lemme restart pc
I really hate the interface of Visual Studio 2022 damn
oki brb
back
do u use the VS22
Yeah
Safe mode, you closed unity with compiler errors last time
It shouldn't interfere with the rest of the config
Yep
Yeah, it doesn't tell you anything unless the generation failed
Now open a script from Unity, you should be done with it
alr
Lemme open the player script
thats the one giving errors
and the one im trying to create a loop in
its open
It doesnt seem to be autocompleting yet though
Oh your gone
Let me know when you're back (if u still want to help me lol)
Just ping me :D
@vagrant wind Do i close the thread or ask someone else?
Sorry I'm back, something important came up
Its alright dont worry
You can stop helping me if you want
I can always ask someone else
Not that close to completing it, no way
Anywhere inside the class, Transform for example
Okay, as long as you have that little list appearing under your cursor as you type, you're good
Do you get errors in the code, underlined red?
Yeah, so it's safe to say that the config succeded
Thats good
first time its working
ive tried so many times
And that, needs to be inside of void Start() for it to be run when the game starts
And the coroutine must be an actual loop for it to repeat
IEnumerator SaveLoop() {
while (true) {
SavePlayer();
yield return new WaitForSeconds(3);
}
}
Otherwise the code is good, apart from the other errors which it seems, are types that you didn't create yet
Well
They are created, but in different scripts
The coroutine seems to not error up now
Its green!
:D
this are the 2 errors now
They were created in
a script called "SaveSystem"
That script got no errors though
so thats alr
I followed a brackeys tutorial
His Player script looked like
1 sec
Yeah, so the first error is because you're referring to something that doesn't exist (it's SaveSystem, not SavePlayer)
And the second one is the same, its Player and not PlayerData
Ah I think it's my fault lmao
This is false. Since LoadPlayer returns a Stats, on line 20 you need to put that in a variable of type Stats, not Player
Yeah, no more errors
because the script name is
Stats
lemme try this
😔
Its fascinating how one can make so many errors in code not longer than 30 lines
I did
and i think i got an idea
Yes
fixed
i had the script without monobehaviour attached to a game object
removing it form a game object removes the error
the tutorial doesnt attach the script
so im figuring that it gets run either way
at start
Yeah, classes that don't inherit from MonoBehaviour cannot be attached to GameObjects, but still can be used for data storage
i see
alr lemme try this
I'll let you know if it works
I just need to make it display the value of coins and gems in text on the screen
and also get it to add to the value
so gimmie a moment
I'll attract your attention on the fact that this is an old tutorial, using old tech.
Especially the BinaryFormatter used to interact with files, is unsafe and should NOT be used anymore.
An attacker can use a maliciously modified save file to exploit a breach in the BinaryFormatter that could give them access to your game, or worse, your computer.
BinaryFormatter is not safe, and cannot be made safe.
See https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide for more information on the subject.
😭
and he said it was the safest and said some other method was unsafe lol
if its not online, is it a security risk?
its bad either way probably
but i am so scared of changing this code because im scared of breaking everything
and im already asking questions on every step
im downgrading to the LTS 2020
And worse, I still can't believe I haven't found a single comment talking about it, all there is is "thanks it works!"
Oflline, there are way less risks. But someone can still send you a save file and be like "hey can you check it? I think it's bugged", and that save file contained a malicious payload
Hm i see
What would you recommend instead
Lemme read the security guide rq
reason i got 2021 was bc of the icon-
i want the new one and not the old one lol
but i can prolly change that
JSON serialization using the safe, built-in type JsonUtility.
But you're getting a bit everywhere, have you fixed the UI issue?
nope
ur corect im everywhere
oki lemme make a list of what i should prioritize
First off, i need to downgrade and get the tools working.
Then i need to fix the UI, and test to see if the code works. (Planning on making it display the value of the variable as text to see if it works)
If it works, i need to use the JSON serialization using the built-in type JsonUtility
oki
getting the 2020 version
LTS
Fixed the arrow issue
@vagrant wind Did you know how to fix the UI issue?
Sorry for the ping, re-added you into the thread.
Let me know if you dont wanna help anymore/cant help anymore
Just give me 10 minutes
Alr!
Alright I'm back
So, what's the issue? Still the anchoring, or the actual text display logic
Oki so
let me try your fix above
i was everywhere and kinda confused myself
u just reminded me
this is the canvas size
this is the scene size
i cant change the canvas size
cant change the canvas size
I'll look it up on google and see if i can find a solution
Yeah it's normal, canvas size can't be changed because it will always fit your whole screen
It has no connection at all with the actual 3d scene
Unity just puts it there because it has nowhere else to render
and i cant get it to be the same size as the camera
Oooh
but what do i do then
the text is affected by the canvas
goes after canvas center etc.
how would i make it fit to the camera center
currently looking it up on google
Yeah, so when you'll play the game the text will be center screen, given that you anchored and positioned it middle center
oooh
this means its anchored, correct?
OMFG
IM SO STUPID
It's always anchored, here middle center specifically
i should have tested
ty
Ui is good enough for now
i just needed it to display the variable
now i just need to switch the system out for JSON serialization
oh that bad
Do you have any recommendations on where i can find out how to switch the system out for JSON serialization?
Unity's documentation for JsonUtility
Nah, it's similar to BinaryFormatter, it may even be easier to use
I know how to use JSON, used it to store economy values for a python bot but
not sure how to do something like that in C#
i think i found something though
U might be right
all i have to change is
from custom to .json
and then some other things
but yes
start seems easy
It works with custom extensions too, as the JSON serializer only returns a string containing the JSON, it's your responsibility to save it anywhere
O
Thats even better
a little bit fun lol
oki so i dont have to change the first step
second step is checking if file exists or not
already got that done
Just keep your current file structure, and class structure, just try to adapt what's being said in that website to your own code
Alr
this part confuses me
it uses void Awake
and makes path
but
cant i just keep what its doing right now
the
Yeah, you just have to change one line in that code, formatter.Serialize
The rest takes care of file I/O
lemme read what they do after i dont know what to change yet lol
wait
i would delete the formatter.Serialize
right?
I remember seeing a post where it said 4 times in the biggest text ever
Yeah, in fact the whole code can be re-designed, because JsonUtility doesn't need a FileStream to work
DONT EVER USE SERIALIZE
And other things about it
But brackeys said use it so i kinda messed up there
O
in the page im reading rn its saying that they are gonna use filestream
but
is there some easier solution if it doesnt need it then?
damn im learning so much
Serializing returns a string, that you can directly write to a file in bulk using the handy File.WriteAllText method, that does all the stream ops for you
would i then do something like
Same thing for reading, but with File.ReadAllText instead
File.ReadAllText
O
and then deserialize that
Yep
it sounds easier but problem is im not sure how i would do that
even though i kinda know
im confused a little lol
Should i do that
or follow the written tutorial thingy that uses FileStream
oh but it does that
now im even more confused
doesnt this method also do ReadAllText
and it looks pretty similar to my code
well not my code but
Working without FileStream is better because you don't handle the stream yourself, eliminating potential errors.
And plus, it shortens the code to about 2 lines
ayo
I like the sound of short code
easier to not fail at
would i have to redesign my whole system though
to use it like that
Not at all, you just have to make your data class serializable, by marking it with that attribute
O
That's all there is to modifying the data layer
Just like in the example on that page
This was another file
Im just guessing rn
That's their example yes
Alr
[Serializable] makes the class visible to JsonUtility, and it will process it
This serializable
Since the JsonUtility will only need to manage the Stats
The thing that you want to serialize, so your Stats class
oh
then im already done
i thought you meant serializing
the save system
now i understand that
now to the main thing
lemme re-read
alr so
now that i made it serializable i just follow the page
i got so confused for a sec
Ah give a minute
something came up sorry
back now
lemme follow the tutoriual
tutorial*
Changed to ^^
@vagrant wind Unity is not happy with me rn
Should i just scrap everything and copy their system?
Its going to do the same thing
Even thought i dont want to copy
this is going so bad
And i've already spent the whole day making no progress
Well, you aren't actually using the JsonUtility anywhere
Neither for saving nor for loading
w h a t
😭
wait
ur right
wtf was i expecting this to do
And saving should not be reading from the file, it should be writing the contents of the JSON to it
Ok so
everything is wrong
No, you're just missing one line of code per method
The one that converts player.Stats to JSON and back
They 100% did, because that's what the article is about, JsonUtility
Yeah that's the one
but it is in the script
above
wait
it isnt
what
now i just need to figure out why everything is red
Inverted, trying to save into the Load, and load into the Save
So if i just
Fixed invertion error
Thats why LoadPlayer is red
thing that doesnt return value is probably
We still have some inversion in the Save. You write before serializing
O
1 sec
Changed order
and added string = path
since the File.Write needs the path
Removed duplibate path under the if (File.exists)
I don't know what GameData is, I recall seeing you take the stats from the player parameter directly
ToJson(Player.stats)
Gamedata should be
I think that was before i used Json
gameData should be
OH WAIT
You still need the same things
so
Player.gameData?
but couldnt i just do
.stats then
Converting the saving system to JSON should not have any effect on the data layer
With BinaryFormatter you got the data from player.stats? That's the same for JSON serialization
Inside of the save method, it's better
Fixed
That method looks good to me
This method is the only one i now kinda understand how it would work
so
if its good then thats even better
again, thank you so much for spending your time here helping me
let me try adding
Stats data = thingy
in the If exists
Hmm no
data is not red lined now
You don't get the stats from thin air, they're in the JSON. You save a Stat, so you deserialize a Stat
LoadPlayer ()
Would i add in the brackets of LoadPlayer (Player Player)
to access Stats data thingy
then
No
oh
The loading loads the stats and returns it that's it
so i'd add the jsonString part from the Saveplayer
and then instead of FIle.WriteAllText i do ReadAllText
Yes, read, then deserialize, and return the value
Alr let me try that
i think im understanding now
do i put the file name here then
player.pepper
O
i think i know what im doing wrong
first off
dont i need string before data
wait
no
wtf
i already read all text
in the path
no wait
im already
cant i just remove the last 2 lines
doesnt it already read
You already read once, yes
But don't delete the line where you convert the read JSON back to a Stats
But it cant be FromJson since thats what this did
That i deleted
I feel so stupid
That's what it does
oh
but cant i just keep the data then if thats what it does
im sorry if im missing something really obvious right now
ToJson converts an object into its JSON representation
FromJson converts a JSON representation into an object
Once you got the data back from the JSON string, just return it, since that's what the method does
It's literally the same thing as the BinaryFormatter, you just change how it's formatted
Nothing else
i shouldnt have deleted the binary formatted thing
There are screenshots of it in this convo
the page doesnt mention anything about return
No
oh
That's taken from the screenshot to show you the logic
aha
Here is how i changed it
am i on the right track or
did i fail miserably
Well, that's wrong, but you've got the logic down
All there is left is to use JsonUtility.FromJson in replacement
.
oh
no errors
did i actually do it
or is this false hope
if i understand
insead of doing as Stats
Not sure, you're not supposed to be passing a file path here
<Stats> is the same thing but
oh
OH WAIT
I WOULD ADD
fileContents THERE
RIGHT?
Yes
PLEASE TELL ME IM RIGHT
OMFG IM UNDERSTANDING
alr now that that is done
if im not mistaken
the easy part
changing text to show the value of coins
i think i can do this myself
only thing i dont know is
where would i put that
would i put that part into the same script
Well the real question is just
How would u get the value now
Ex. From another script how would I load it
And
Yes
If I know how to load it o can use the coins variable
And modify it before saving for example
Ao all I need to know is that
If you did not touch any other code, you are already doing it somewhere.
Like Stats s = SaveLoadSystem.LoadPlayer();
So right after that, you can access s to pull the coin count and display it
O
So
s.xoins
Coins*
Or
s.gems
I see
And I can do that in any script if I'm not wrong
Correct?
I might have to define Stats
But isn't that it
If I try to access the variables from another script
No, you can't do that from any script. You need a reference to the Stats you just loaded
Usually in the script you have a reference to the text, and set the text from there
Stats s = SaveLoadSystem.LoadPlayer();
theText.text = s.coins;
Reference the text, it's easier
Alr so
I just use the script called SaveSystem (the one with load player and save player) to manage anything that requires loading
That sounds a little more orginazied actually smart
And when I save
Is gonna save the current value of coins
If I didn't mess it up
Lemme try
Again third time, tysm for bearing with me and spending your own time on helping me
If I remember correctly you already have a script that does SaveSystem.LoadPlayer(), I helped you fix it
Yes
So use that very script and apply this.
Let me try this sorry unity is loading
oh i wrote a double ;; thats why i got an error
1 sec
this is where it is
but thats in another script
hm
oh it does the same thing
but remakes the LoadPlayer function
but just loads everything from the SaveSystem Load player
So that's the code you had from the beginning, and it's on the Player script
Correct
and if im not wrong
it does the same thing
just in another script
which i could use instead of the SaveSystem script to make the SaveSystem script less cluttery
If you don't spawn your player (ie. if it's into your scene before you start the game), you can have a direct reference to the Text from there, and update the text from the player
so if the text object is in the scene before i start the game
i can just do something like
Text.value = "" <- that is completly wrong i'll check how to do that im just using it as an example for a reference
https://forum.unity.com/threads/changing-textmeshpro-text-from-ui-via-script.462250/ found what im looking for
If both* the player and the text object are in the scene, then yes
hm
so the 3 scripts i have
are
in here
does that count as scene
No
That's your project files
In the scene = scripts attached to GameObjects in the scene
so i could make an empty game object called
idk
Scripts
and attach the scripts to it?
Well the player one
the other 2 dont have a mono behaviour
I think you have a fundamental misunderstanding of everything Unity, and all of this is way over your head
So you should be doing tutorials, because tomorrow you won't remember how the JSON save/load system works
i've tried tutorials
But
they are often for
specific parts of something
and not full
No, real tutorials, that get you started with Both Unity and C#
You would need to do at least the three first that are pinned to #💻┃code-beginner
To be honest, you won't be able to get this working because you don't have the fundamentals of how scripts can communicate and what references are
It would be better to drop the current project, do the tutorials, and come back to the project
i see
omg wait
its working
I added a LoadPlayer(); to the Start();
before it starts saving
Thank you so much for helping me
I'll put this project on pause
and check out the tutorials up there
Again thank you for spending so much time helping someone who doesnt know anything at all
I just realized that we never actually tested the code, but if it works it's good, you won't have to scratch your head bugfixing later on
So off you go to tutorials now!
Yes i was scared of that lol
I remembered that we had to load
tried and
it works
Tysm
I will master unity
And i will dm you one day saying
i understand
Tysm
Have a good day!
The thread will archive itself if im not wrong
I'm looking forward to this moment. All of this started from an IDE config issue lmao