#IDE Configuration

1 messages · Page 1 of 1 (latest)

vagrant wind
#

There we go

meager snow
#

Thank you

#

Both for making a thread and being patient enough to help me

vagrant wind
#

So, you're using Visual Studio Code, which is entirely different from Visual Studio, even if the names don't differ that much

meager snow
#

wait

#

waaaaait a sec did i click the wrong link maybe

#

also

#

should i switch IDE?

vagrant wind
#

If you have a decent computer I would advise dropping VS Code and installing Visual Studio 2022

vagrant wind
#

It's heavier, but it installs 100 times faster. No package and extensions needed

#

It's fully built-in

meager snow
#

I see

#

So takes more space but got everything built in

#

lemme uninstall this one then

#

getting 2022 rn

vagrant wind
#

Community, the other two are for professionals and paid

meager snow
#

I wish i could lie and say im a professional lol

vagrant wind
#

If you want to pay $2500 per year, sure

meager snow
vagrant wind
#

Just let me know when the install is complete and when it prompts you to install "workloads"

meager snow
#

Alr

#

Installed its getting ready

vagrant wind
#

Installer is (yet) another application that you can run to manage what workloads are installed on your system

meager snow
#

Its done

#

Prompting me to install workloads now

vagrant wind
#

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"

meager snow
#

Alr

#

this one it is

vagrant wind
#

Yes

meager snow
#

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?

meager snow
vagrant wind
#

You can select the workload so VS supports editing Python scripts, but not sure if it'll install other versions of Python with it

meager snow
#

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!

vagrant wind
#

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

vagrant wind
#

Once the install completes you can close the installer, and switch back to Unity, to finish the config on that side

meager snow
#

soon done

meager snow
#

Its done

#

Lemme just sign in

#

I'll probably get used to the start menu

#

Alr then time for the unity side

vagrant wind
#

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

meager snow
#

do i browse

vagrant wind
#

Hmm, it should be there

meager snow
#

and try to find Visual Studio 2022

#

I could try to re-open unity

vagrant wind
#

Maybe the whole computer, so VS things go in the PATH

meager snow
#

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

vagrant wind
#

Yeah, here it failed to load

meager snow
#

alr

vagrant wind
#

"Misc files" and uncolored Unity types are hints

meager snow
#

alr

#

lemme restart pc

#

I really hate the interface of Visual Studio 2022 damn

#

oki brb

#

back

#

do u use the VS22

vagrant wind
#

Yeah

meager snow
#

alr

#

opening unity

vagrant wind
#

Safe mode, you closed unity with compiler errors last time

#

It shouldn't interfere with the rest of the config

meager snow
#

Alr

#

So now i just try the thing again

#

external tools

vagrant wind
#

Yep

meager snow
#

Got it

#

Regenerating project files now

#

and its done i think

vagrant wind
#

Yeah, it doesn't tell you anything unless the generation failed

#

Now open a script from Unity, you should be done with it

meager snow
#

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

meager snow
#

@vagrant wind Do i close the thread or ask someone else?

vagrant wind
meager snow
#

You can stop helping me if you want

#

I can always ask someone else

vagrant wind
#

Not that close to completing it, no way

meager snow
#

Alright

#

:D

#

Can you give me an example of something it should autocomplete

vagrant wind
#

Anywhere inside the class, Transform for example

meager snow
#

alr

#

Autocompleted Trans to Transform so i think its working

vagrant wind
#

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?

meager snow
#

let me check

#

Console

#

All are from Line 21

#

which is

vagrant wind
#

Yeah, so it's safe to say that the config succeded

meager snow
meager snow
#

first time its working

#

ive tried so many times

vagrant wind
# meager snow

And that, needs to be inside of void Start() for it to be run when the game starts

meager snow
#

alr

#

1 sec

#

green means its not giving any errors on that part?

vagrant wind
#

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

meager snow
#

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

vagrant wind
#

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

meager snow
#

OHH

#

let me try now

#

Only 1 error left now!

#

let me check line 20 rq

vagrant wind
#

Ah I think it's my fault lmao

vagrant wind
meager snow
#

Lemme re-read

#

im so confused

#

hmm

#

So i do

vagrant wind
#

Yeah, no more errors

meager snow
#

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

vagrant wind
#

Uhh never seen that one

#

Not a C# error, at least

meager snow
#

Hmm

#

wait

#

is it maybe because i removed : Monobehaviour

vagrant wind
#

No idea

#

Refer to the tutorial, compare your code to theirs in the video

meager snow
#

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

vagrant wind
#

Yeah, classes that don't inherit from MonoBehaviour cannot be attached to GameObjects, but still can be used for data storage

meager snow
#

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

vagrant wind
#

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.

meager snow
#

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

vagrant wind
#

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

meager snow
#

What would you recommend instead

#

Lemme read the security guide rq

meager snow
#

i want the new one and not the old one lol

#

but i can prolly change that

vagrant wind
meager snow
#

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

meager snow
#

very late but im back

#

its finally installed

#

currently downgrading the project

meager snow
#

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

vagrant wind
#

Just give me 10 minutes

meager snow
#

Alr!

vagrant wind
#

So, what's the issue? Still the anchoring, or the actual text display logic

meager snow
#

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

vagrant wind
#

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

meager snow
#

oh

#

but the text is in it

vagrant wind
#

Unity just puts it there because it has nowhere else to render

meager snow
#

and i cant get it to be the same size as the camera

meager snow
#

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

vagrant wind
#

Yeah, so when you'll play the game the text will be center screen, given that you anchored and positioned it middle center

meager snow
#

this means its anchored, correct?

#

OMFG

#

IM SO STUPID

vagrant wind
#

It's always anchored, here middle center specifically

meager snow
#

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?

vagrant wind
#

Unity's documentation for JsonUtility

meager snow
#

O

#

Pasting this here

#

this is gonna be complicated

#

damn

vagrant wind
#

Nah, it's similar to BinaryFormatter, it may even be easier to use

meager snow
#

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

meager snow
#

all i have to change is

#

from custom to .json

#

and then some other things

#

but yes

#

start seems easy

vagrant wind
#

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

meager snow
#

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

vagrant wind
#

Just keep your current file structure, and class structure, just try to adapt what's being said in that website to your own code

meager snow
#

this part confuses me

#

it uses void Awake

#

and makes path

#

but

#

cant i just keep what its doing right now

#

the

vagrant wind
#

Yeah, you just have to change one line in that code, formatter.Serialize

#

The rest takes care of file I/O

meager snow
#

O

#

Alr

meager snow
#

wait

#

i would delete the formatter.Serialize

#

right?

#

I remember seeing a post where it said 4 times in the biggest text ever

vagrant wind
#

Yeah, in fact the whole code can be re-designed, because JsonUtility doesn't need a FileStream to work

meager snow
#

DONT EVER USE SERIALIZE
And other things about it
But brackeys said use it so i kinda messed up there

meager snow
#

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

vagrant wind
#

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

vagrant wind
#

Same thing for reading, but with File.ReadAllText instead

meager snow
#

File.ReadAllText

meager snow
#

and then deserialize that

vagrant wind
#

Yep

meager snow
#

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

meager snow
vagrant wind
#

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

meager snow
#

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

vagrant wind
#

Not at all, you just have to make your data class serializable, by marking it with that attribute

vagrant wind
#

That's all there is to modifying the data layer

meager snow
#

To make is serializable

#

do i put

#

[System.Serializable]

vagrant wind
#

Just like in the example on that page

meager snow
#

Im just guessing rn

vagrant wind
#

That's their example yes

meager snow
#

Alr

vagrant wind
#

[Serializable] makes the class visible to JsonUtility, and it will process it

meager snow
#

O

#

But dont i only need to make the

#

file containing

meager snow
#

Since the JsonUtility will only need to manage the Stats

vagrant wind
#

The thing that you want to serialize, so your Stats class

meager snow
#

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

meager snow
#

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

vagrant wind
#

Well, you aren't actually using the JsonUtility anywhere

#

Neither for saving nor for loading

meager snow
#

😭

#

wait

#

ur right

#

wtf was i expecting this to do

vagrant wind
#

And saving should not be reading from the file, it should be writing the contents of the JSON to it

vagrant wind
#

No, you're just missing one line of code per method

meager snow
#

wait

#

i am?

#

ur making me see hope in the far too long time i've spent

vagrant wind
#

The one that converts player.Stats to JSON and back

meager snow
#

i dont think they included that

#

oh god

#

isnt this it?

vagrant wind
#

They 100% did, because that's what the article is about, JsonUtility

#

Yeah that's the one

meager snow
#

but it is in the script

#

above

#

wait

#

it isnt

#

what

#

now i just need to figure out why everything is red

vagrant wind
#

Inverted, trying to save into the Load, and load into the Save

meager snow
#

Fixed invertion error

#

Thats why LoadPlayer is red

#

thing that doesnt return value is probably

vagrant wind
#

We still have some inversion in the Save. You write before serializing

meager snow
#

O

#

1 sec

#

Changed order

#

and added string = path

#

since the File.Write needs the path

#

Removed duplibate path under the if (File.exists)

vagrant wind
#

I don't know what GameData is, I recall seeing you take the stats from the player parameter directly

#

ToJson(Player.stats)

meager snow
#

Gamedata should be

meager snow
#

gameData should be

#

OH WAIT

vagrant wind
#

You still need the same things

meager snow
#

WAIT

#

IS gameData A VARIABLE INSIDE OF THE SCRIPT

#

WAIT

#

no

#

it isnt

meager snow
#

Player.gameData?

#

but couldnt i just do

#

.stats then

vagrant wind
#

Converting the saving system to JSON should not have any effect on the data layer

meager snow
#

aha

#

then imdeleting the gameData

#

no im not

#

Because im unsure of what it does

vagrant wind
#

With BinaryFormatter you got the data from player.stats? That's the same for JSON serialization

meager snow
#

1 sec

#

wait

#

so i do

vagrant wind
#

Inside of the save method, it's better

meager snow
meager snow
vagrant wind
#

That method looks good to me

meager snow
#

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

vagrant wind
#

Hmm no

meager snow
#

data is not red lined now

meager snow
#

removed

#

do i need to add

#

in the

vagrant wind
#

You don't get the stats from thin air, they're in the JSON. You save a Stat, so you deserialize a Stat

meager snow
#

LoadPlayer ()

meager snow
#

to access Stats data thingy

#

then

vagrant wind
#

No

meager snow
#

oh

vagrant wind
#

The loading loads the stats and returns it that's it

meager snow
#

o

#

hm

meager snow
vagrant wind
#

Yes, read, then deserialize, and return the value

meager snow
#

Alr let me try that

#

i think im understanding now

#

do i put the file name here then

#

player.pepper

vagrant wind
#

No, the type

#

Stats

meager snow
#

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

vagrant wind
#

You already read once, yes

#

But don't delete the line where you convert the read JSON back to a Stats

meager snow
#

to convert back i do

#

this one

#

right?

#

but add a string before the data

vagrant wind
#

No, FromJson<Stats> returns a Stats, not a string

#

So Stats data = JsonUtility...

meager snow
#

i swear im stupid

#

How would i convert it back to a stats

#

FromJson?

meager snow
#

That i deleted

#

I feel so stupid

vagrant wind
#

That's what it does

meager snow
#

but cant i just keep the data then if thats what it does

#

im sorry if im missing something really obvious right now

vagrant wind
#

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

meager snow
#

OH

#

so i'd do

#

return data;

vagrant wind
#

It's literally the same thing as the BinaryFormatter, you just change how it's formatted

#

Nothing else

meager snow
#

i shouldnt have deleted the binary formatted thing

vagrant wind
#

There are screenshots of it in this convo

meager snow
#

the page doesnt mention anything about return

vagrant wind
meager snow
meager snow
#

just copy exactly that

#

oh

vagrant wind
#

No

meager snow
#

oh

vagrant wind
#

That's taken from the screenshot to show you the logic

meager snow
#

aha

meager snow
#

am i on the right track or

#

did i fail miserably

vagrant wind
#

Well, that's wrong, but you've got the logic down

#

All there is left is to use JsonUtility.FromJson in replacement

meager snow
#

would i do

#

.Deserialize

#

after FromJson

vagrant wind
meager snow
#

oh

#

no errors

#

did i actually do it

#

or is this false hope

#

if i understand

#

insead of doing as Stats

vagrant wind
#

Not sure, you're not supposed to be passing a file path here

meager snow
#

<Stats> is the same thing but

meager snow
#

OH WAIT

#

I WOULD ADD

#

fileContents THERE

#

RIGHT?

vagrant wind
#

Yes

meager snow
#

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

vagrant wind
#

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

meager snow
#

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

vagrant wind
#

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

meager snow
#

So

#

If I just reference the stats

#

I can do it from another script

vagrant wind
#
Stats s = SaveLoadSystem.LoadPlayer();
theText.text = s.coins;
#

Reference the text, it's easier

meager snow
#

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

vagrant wind
#

If I remember correctly you already have a script that does SaveSystem.LoadPlayer(), I helped you fix it

meager snow
#

Yes

vagrant wind
meager snow
#

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

vagrant wind
#

So that's the code you had from the beginning, and it's on the Player script

meager snow
#

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

vagrant wind
#

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

meager snow
#

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

vagrant wind
#

If both* the player and the text object are in the scene, then yes

meager snow
#

so the 3 scripts i have

#

are

#

in here

#

does that count as scene

vagrant wind
#

No

#

That's your project files

#

In the scene = scripts attached to GameObjects in the scene

meager snow
#

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

vagrant wind
#

I think you have a fundamental misunderstanding of everything Unity, and all of this is way over your head

meager snow
#

Pretty much yes

#

but you only learn one way-

vagrant wind
#

So you should be doing tutorials, because tomorrow you won't remember how the JSON save/load system works

meager snow
#

But

#

they are often for

#

specific parts of something

#

and not full

vagrant wind
#

No, real tutorials, that get you started with Both Unity and C#

meager snow
#

I didnt even notice those

#

I guess i need to check those out when i get this working

vagrant wind
#

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

meager snow
#

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

vagrant wind
#

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!

meager snow
#

At first it didnt work but

meager snow
#

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

vagrant wind
#

I'm looking forward to this moment. All of this started from an IDE config issue lmao

vagrant wind
#

...8 hours ago

#

Look how far we've gone