#💻┃code-beginner

1 messages · Page 819 of 1

inland pecan
#

nvm

naive pawn
#

you'd want to set the min to -50 then, not the max

grand snow
#

yes well said, otherwise the newly gained euler angles are 0-360 which are harder to clamp without extra effort

lethal gull
#
        direction.y = 0f;
        float angle = Vector3.SignedAngle(listener.forward, direction, Vector3.up);
        float pan = Mathf.Clamp(angle / 90f, -1f, 1f);
        directionSourceTwo.panStereo = pan;``` hi, I'm trying to get where the target is compared to the listener and make the stereo value based on that, I really didn't know how to do this so I found this on google but it doesn't work, how could I fix this?
grand snow
# lethal gull ``` Vector3 direction = target.position - listener.position; direction.y...

I wanted to try myself so here is a complete solution:

using UnityEngine;

public class AudioPan2D : MonoBehaviour
{
    [SerializeField]
    AudioSource audioSource;

    [SerializeField]
    Transform target;

    [SerializeField]
    float panRangeMax;

    private void Update()
    {
        Vector2 dir = target.position - transform.position;
        float distance = dir.magnitude;
        dir.Normalize();
        audioSource.panStereo = Vector2.Dot(Vector2.left, dir) * Mathf.Clamp01(distance / panRangeMax);
    }

    private void OnDrawGizmosSelected()
    {
        Gizmos.DrawWireSphere(transform.position, panRangeMax);
    }
}
#

I realised it needed a range where it slowly pans vs an instant jump so thats in there too

echo copper
#

guys, how can i change an order in layer of textmeshpro?

grand snow
echo copper
grand snow
#

So moving the game object up/down the hierachy changes this.
If you need to force it to draw on top of things you can use a canvas with override sort order BUT this is not a good solution for many objects.

echo copper
#

oh, well. every object in menu is on canvas. i guess it's not good...

grand snow
#

Usually you just need the 1 canvas and maybe a few sub ones for large "popups" or menus

echo copper
#

i get it. well, idk why but tmp doesn't show up in game window. only in scene window

grand snow
#

Toggle 2d mode in the scene view and check if the text has some crazy Z position

echo copper
#

0 z

#

idk what can i do

hexed terrace
#

move to #📲┃ui-ux and post (non-cropped) screenshots of the issue and setup

willow bear
#

can someone help me with my code?

hexed terrace
radiant voidBOT
# hexed terrace !ask

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

sage mirage
#

Hey, guys! I was wondering what the WorldPositionStays does in SetParent() method? What I mean is whats the difference between false and true because I cant understand the difference and I read the documentation about it. I just want visual example.

grand snow
#

Transforms actually only store local position and that is relative to its parent

sage mirage
#

I have to actually see what is happening I cant understand

#

Let me see on my project

#

because I have some doors and I want my open and close audio sources to be attached to them as childs

#

I did it and it works

#

I just want to understand what is going on with world position stays exactly

cosmic cradle
keen cobalt
#

can someone help me why my menu is colliding with this and doing this when ive made a build to test it

keen dew
#

Here's a visual example: Let's say there's a ball in box A. The ball is the child of the box. You then use SetParent to make the ball a child of box B. If WorldPositionStays is true, the ball changes parent but stays inside box A. If WorldPositionStays is false, it moves inside box B.

grand snow
keen cobalt
grand snow
sage mirage
keen cobalt
grand snow
#

fyi the unity inspector always shows local position for transforms

grand snow
sage mirage
#

I know what relative to its parent means

#

like visually

#

what it does

#

I have to check it out on my own

#

give me a minute otherwise I cant figure out

grand snow
#

false: just change parent and THATS IT

keen cobalt
#

what would be a good achor for it cuz im struggling ive done it before but idk @grand snow

grand snow
#

You would be better reading the full documentation unity has on UI layout

keen cobalt
#

i am but im confused lol

grand snow
sage mirage
#

so when its true the childrent of the parent stays at the exact position that he was before being a children right and if its false then it doesn't stay and it goes relative to its parent leaving its original position behind right?

#

Thats the logic of WorldPositionStays?

grand snow
#

By "exact position" being their world position then correct

sage mirage
#

Yes its world like where it was in world before being a child

grand snow
#

Yes

#

Extra work is needed to maintain that world position when changing a transforms parent

sage mirage
#

It says keep the child game object at its original world position as before being a child and if false then just attach it straighforward to the parent game object so the child game object abandons its original world position and change relative to its parent thats what I understand.

grand snow
#

You have it backwards. A transform actually only stores local position and local rotation

#

So changing a transforms parent without doing anything else would likely mean its world position would move

#

So to wrap this up. Keep world position restores the transforms world pos after changing parent

sage mirage
#

what I understand is when true the child object keeps its old original position, if its false the child is going to have the same coordinates as its parent object. Just tell me is it right?

grand snow
#

fuck it yes

#

i sense a miss understanding but close enough

#

just test yourself if you need to see stuff move tryitandsee

sage mirage
#

Ok I think I can undestand what WorldPositionStays does right now.

#

I just wanted to really get into the logic

#

And basically its what the name of the parameter says World Position Stays so if its true keep the origin position of the child object

keen cobalt
#

should this effect it

sage mirage
#

I mean yes it makes sense

keen cobalt
sage mirage
#

for Ps2 or Ps5 exclusively?

#

I remember playing ps2 ben 10

#

Alien Force if I remember

keen cobalt
#

no im making it cuz i want one but im confuesed why unity is doing that to that scene n shit

sage mirage
#

Just note me down I will be playing it

#

I am a fan of Ben

keen cobalt
keen cobalt
grand snow
#

yea pinging random people will get them to help

#

Your camera needs to have a skybox or solid colour background

sage mirage
keen cobalt
#

i dont really like talking to ppl on call

#

@sage mirage soz

#

but u can tell me here

#

@grand snow this happens when its solid

sage mirage
#

YOu can even see who I am XD

lethal gull
keen cobalt
#

i just dont like to in general

sage mirage
#

ok provide more context then

#

It would be really nice if you could record your screen using OBS

keen cobalt
#

lemme record a thing one sec

sage mirage
#

and show exactly what is going on

grand snow
lethal gull
keen cobalt
grand snow
keen cobalt
grand snow
#

The audio source still needs to be placed where it physically is in 2d space

lethal gull
lethal gull
grand snow
lethal gull
lethal gull
grand snow
#

No audio but what I hear is what i expect

#

When the source is to the right of my camera it pans to the right

solar hill
#

I thought their project was a 3d game no UnityChanThink would that not affect certain things

grand snow
#

In 3d we just use what unity provides

lethal gull
# grand snow I think the logic is fine

OH YEA, that's why you put in a maxpandistance, you're in 2D game, in my case, what I wanted is the pan to be 1 if the audiosource is on the listener's right and vice versa, not with distances or anything

lethal gull
grand snow
#

Put spatial blend to 3d

solar hill
grand snow
#

Then it works like real life

solar hill
#

if this is the same issue they had yesterday

grand snow
#

Oh right so the normal 3d blending is not desired?

solar hill
#

yeah

grand snow
#

I honestly presumed this was for 2d based on the request haha

solar hill
#

i recognized it as the same problem they had yesterday, i so remembered it was indeed 3d

grand snow
#

Are the 3d sound settings not sufficient to solve this either?

solar hill
#

they said they tried them and it didnt work UnityChanThink

grand snow
#

User error?

solar hill
#

i think this would be a lot more productive of a conversation if @lethal gull you created a large message explaining the issue, what you tried, what you are trying right now, and what you want accomplished

lethal gull
# grand snow Put spatial blend to 3d

this doesn't work, the sound provenance still is kinda global and further you are from the audiosource, the less u hear it so this just doesn't work at all$

grand snow
#

The solution to this in 3d is more complex as it's based on camera rotation

elfin pike
#

Im stuck with one issue. I have ScriptableObjects, each has its own id. I have to get object by id

lethal gull
solar hill
#

also the stereo panning approach will leave a lot of ambiguity with front and back positions

lethal gull
elfin pike
rich adder
elfin pike
rich adder
#

if you're so worried thats why thread exist too.
anyhow, which id are you talking about , the asset itself ? what do you need to do ?
this smells like an xyproblem?

elfin pike
rich adder
#

ok but thats vague.. what do you need to do ?
you stored a GUID on your SO and you want to grab the GUID or wat

#

its hard to know what your intentions are if you don't explain them lol

#

you want to grab the SO with your own GUID, but is this a runtime search? editor ?

elfin pike
#

I have folder with SO and IDs. i have to get SO using ID

rich adder
#

there are a myriad of ways of doing something, the best suggestion comes in when you explain the problem clearer

rich adder
#

the most brute force way is probably not the best but you can scan the folder until you find the ID you're looking for with basic loop

elfin pike
rich adder
#

IO can be slow though.. is it not possible to just store the references in a script already or wat?

#

are you doing this during runtime or in the editor ?

elfin pike
#

i should create class, which stores in dictionary ref and id? can i add or remove if SO is created or removed?

rich adder
#

dictionary could work sure, you still need to initially add them

#

maybe you could put them into another SO

#

You could probably automate the process

elfin pike
#

Anybody here have worked with IDs?

grand snow
#

Ofcourse

#

how else do we refer to things in a reliable way?

#

Numerical or string guid/name based ids are what i go with

elfin pike
rich adder
#

yesterday I learned about Hash128 if you need some extra speed above storing string / lookup
Dictionary<Hash128, MyThing>
instead of
Dictionary<string, MyThing>

grand snow
#

If a human is assigning ids then id just leave this job to Dictionary

#

If i were to configure items with scriptable objects or json id use string based id names

#

If you load them all into a dictionary then you will find out quickly about duplicate ids (presuming you use .Add())

elfin pike
grand snow
#

scriptable object or something else?

#

because OnValidate does not sound like the place

#

If you are generating this id in code i would use a numerical id instead

#

If you know all other ids you can pick the max + 1

elfin pike
#

I have LevelData as SO. i store them in folder. and have to get one of them

#

using IDs, because im referencing in json file

grand snow
#

Yea then what i said above is what I think

elfin pike
#

so dictionary is best optionn?

grand snow
#

Two things to consider:
The id type
Fast lookup using id

cosmic cradle
#

Hash128 isn't serializable. Is there some alternative to strings that can be serialized by Unity?

grand snow
#

byte array

#

you can use the serialization callback interface to perform the conversion

#

@cosmic cradle

elfin pike
grand snow
# elfin pike what are the options?

Numerical types should be best because they can be hashed quickly or be used as is.
a long guid may not be as fast but are easier to use if you want to generate a unique one without extra effort

#

Id not worry about it too much unless you experience bad performance

elfin pike
#

you also use dictionary?

grand snow
#

Oh yes all the time

#

You really only have 3 choices for id to object lookup:

  • loop and compare till you find it
  • use a dictionary
  • some custom solution thats probably slower
rich adder
#

as collection grows dictionary/hashset usually always faster

elfin pike
#

its class with dictionary? or you add something extra?

grand snow
#

Dictionary<uint, Item> items bam

#

whatever stores your data after loading can keep them in a dictionary

elfin pike
#

Maybe i should create SO for this purpose

keen cobalt
grand snow
rich adder
#

not a coding question at all.. if you lookup replace unity armature you will find plenty of videos on this

keen cobalt
#

ive tried man thats why im looking for help

rich adder
#

then ask about where you got stuck instead, if you're not willing to put effort into your own problem how will people help you ?

keen cobalt
rich adder
#

literally put the model in, generate the humanoid armature avatar and put it as child .. use the avatar in the animator

keen cobalt
#

no need to put it so rudely man i was just seeing if someone was willing to help

grand snow
#

You are asking for someone to just do shit for you

keen cobalt
#

no im not i said help

elfin pike
keen cobalt
grand snow
elfin pike
rich adder
grand snow
keen cobalt
grand snow
#

Anyway Ive done this for years, json configuration with ids do as you will

rich adder
keen cobalt
#

no

#

i just asked for help man relax

cinder schooner
#

lol

rich adder
#

this is for coding , you're not asking a coding question

#

wow look at that even the official unity channel has the How to do this..
https://youtu.be/4QuPlKzdq14?t=452

Starter Assets are designed to work as a quick start into prototyping and developing character controllers for various game genres, using systems and methods that are easy to build and expand upon for different projects.

▶ Read more on the Starter Assets https://on.unity.com/3gvKQAX
▶ Technical questions and support https://on.unity.com/3cZ...

▶ Play video
elfin pike
#

i have another question, which probably multiple people want to know. Is there way to make updates to game. Okay, my game is small and people dont mind downloading game multiple times, but if its bigger

solar hill
#

this is really something you have to handle with the place youre distributing your game

#

and not much to do within unity

rich adder
#

so you can with some stuff specifically but in most cases you have to replace

foggy yoke
#

i'm trying to get the binding index for my "Spell" action with playerInput.actions.FindAction("Spell").GetBindingIndex() (I checked and the name matches), but it's getting the binding index of my "Move" action. I tried to get both the spell and move actions' index, and it returned the same int, 0. What should I do? csharp int shootSpellActionEventIndex = playerInput.actions.FindAction("Spell").GetBindingIndex(); int moveActionEventIndex = playerInput.actions.FindAction("Move").GetBindingIndex();

wintry quarry
#

You're not passing in any path or group, so of course it's going to give you 0

foggy yoke
wintry quarry
#

Since you provided no parameters it will just map with the first binding

wintry quarry
#

why are you looking at bindings?

#

playerInput.actions.FindAction("Spell").performed += SpellListener;

foggy yoke
#

i searched for how to do this exactly and they said that

wintry quarry
#

IDK what you searched or what you were rreading but that's very incorrect

#

you must be misunderstanding something

foggy yoke
#

thank you!

wintry quarry
#

performed, canceled, or started

foggy yoke
wintry quarry
#

you set it up in the inspector

#

on the PlayerInput component

rich adder
#

UnityEvent is for inspector

#

you can sub to it but thats defeat the point

wintry quarry
#

Don't forget to pres the little arrow/carrot next to "Events" in the inspector to expand that section

#

then you can assign your listeners there

foggy yoke
#

that's why I want to assign it via code

wintry quarry
#

Is the PlayerInput component on a different object than the script that you want to listen to the events?

wintry quarry
#

don't do that

foggy yoke
#

but I have to

wintry quarry
#

you don't have to

#

you can add a layer of indirection

#

Anyway if you want to use UnityEvents that goes against that whole idea

#

So either:

  • Switch away from UnityEvents
    or
  • Subscribe in code
foggy yoke
#

thank you!

rich adder
#

generate the C# class you can have inputs where you want and skips Player component entirely

wintry quarry
#

that has other issues though

#

then you have to manage your own instance and it can get tricky with rebinding etc

#

definitely a viable option if you're prepared to do that

rich adder
#

yea true

wintry quarry
#

Also tricky if there's local multiplayer...

rich adder
#

I try not to do it often but, there is also InputActionReference for scripts that only care for specific keys and you don't have to manage your own input class but yea has its own drawbacks

#

its an SO so never breaks between scenes

sage mirage
#

Hey, guys! I see that GameObject class has 3 different FindGameObject with tag methods. First one is FindWithTag and the second one is FindGameObjectWithTag I mean whats the difference? Also the third one is the one that stores the object references on an array but tell me specifically about these 2 methods

wintry quarry
sage mirage
wintry quarry
sage mirage
potent portal
#

im so confused, why is it giving an error yet it works completely fine??

wintry quarry
#

the difference is just plural vs not plural

sage mirage
wintry quarry
rich adder
wintry quarry
potent portal
sage mirage
#

I mean Yes but this is for the other method

sage mirage
naive pawn
potent portal
#

thanks!

naive pawn
#

you should be able to use the search bar as well

wintry quarry
#

It's preferences not project settings

naive pawn
#

ah whoops

#

yeah that makes sense

sage mirage
#

So, what is going to happen if I am going to use FindGameObjectsWithTag()?

wintry quarry
naive pawn
wintry quarry
#

yeah

sage mirage
#

I mean what deprecated does and is?

potent portal
#

wait it is?

sage mirage
#

I think deprecated is out dated

rich adder
#

I thought textmeshpro was now part of unity namespace

wintry quarry
#

it means they're removing it from the API and it won't exist in future versions

sage mirage
#

maybe

naive pawn
sage mirage
#

They no longer support probably

wintry quarry
potent portal
#

no?

wintry quarry
#

What verison of Unity are you on @potent portal

potent portal
#

6000.0.68f1

naive pawn
wintry quarry
potent portal
#

i am following a course from last year so idk

naive pawn
#

there it is

#

wait no last year isn't very old

wintry quarry
naive tapir
#

Does anyone know how I can get this to fully overwrite the old file instead of just, adding onto it?

naive pawn
#

oh god it's 2026 already notlikethis

sage mirage
potent portal
sage mirage
#

What is it

#

What is deprecated?

wintry quarry
sage mirage
#

deprecated means old

#

So I just translate it

rich adder
#

replaced with something new

naive pawn
potent portal
naive pawn
#

wait you already have that

naive tapir
naive pawn
#

@naive tapir you seem to already be specifying overwrite mode. are you sure you're looking at the right file/output? try debugging the finalFile value that you're writing

sage mirage
#

One says that its not about support and @rich adder says its about support. What is deprecated?

potent portal
#

regenerating the project files helped!

rich adder
naive pawn
naive tapir
sage mirage
sage mirage
naive pawn
#

@sage mirage please learn to google. it's a crucial skill. these explain adequately

rich adder
#

yeah means they dont actively work on that method anymore

#

hence " you should switch to yada yada"

sage mirage
rich adder
#

can you not shitpost ty.

naive pawn
sage mirage
#

No Unity is the problem here

rich adder
#

they usually give you the alternative right in the deprecated message

sage mirage
#

They write deprecated in some methods and on some others they dont

#

XD

naive pawn
#

wtf are you on about

sage mirage
#

FindGameObjectWithTag()

#

its not deprecated

#

because it doesn

naive pawn
#

ok?

rich adder
#

right so that mean you can use it fine?

sage mirage
#

What I wanted to say is what s the difference between find with tag and find game object with tag

rich adder
#

rigidbody.velocity deprecated
rigidbody.linearVelocity the new method

rich adder
sage mirage
#

It says retrieves the first active game object with tag

#

in docw

#

docs

#

I dont see the FindGameObjectWithTag on docs

#

XD

rich adder
#

yeah its always been that way

sage mirage
#

Why I can use it and it isn't in the docs

#

I mean what

naive pawn
#

this is one of the parts of deprecation

#

it's not going to be maintained

#

that includes docs

sage mirage
#

Its not deprecated bro

#

No

rich adder
#

its been missing in the docs ever since I've used unity tbh

sage mirage
#

There is no deprecated somewhere written

#

wait maybe its hiding

naive pawn
#

ah, ok, i was thinking of the find of type thing

#

guess it just isn't documented then

rich adder
#

yeah its been that way at least from 2017 from what i recall

sage mirage
#

so I can just use find with tag

#

and thats it

naive pawn
#

that.. isn't particularly strange, especially when there's a well-documented alias

slender nymph
#

They are actually just the same thing, FindWithTag just calls FindGameObjectWithTag

rich adder
#

good to know.
haven't used a tag since 2019

#

aside from the weird implementations that still exist in some unity components, looking at you cinemachine..

cosmic dagger
#

Yep, it just calls the original version. The problem was the original is too similar to the plural version FindGameObjectWithTag and FindGameObjectsWithTag, which returned an array. FindWithTag is easier to type and differentiate with FindGameObjectsWithTag . . .

rich adder
toxic ledge
rich adder
solar hill
#

👇

radiant voidBOT
# solar hill 👇

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

rich adder
toxic ledge
rich adder
toxic ledge
#

Well is just becas im doing the unity totrial for collect the collectible and i did how they explain but i cant and it olso shows me this error

rich adder
#

read the error message it usually tells you exactly whats wrong

#

make sure you followed the tutorial exactly

toxic ledge
toxic ledge
rich adder
#

show the script

toxic ledge
rich adder
naive pawn
rich adder
#

where else am i supposed to go whenever i procastinate on my own projects xD

toxic ledge
cosmic dagger
#

!code

radiant voidBOT
toxic ledge
#

Ok i feel emberesed now -//-

naive pawn
#

everyone has a first, all good

#

-# better this than being stubborn/arrogant tbh

toxic ledge
#

do i like just post the link or what then..

rich adder
toxic ledge
solar hill
#

feels like a simple fix no? do you have a rigidbody on your cylinder?

rich adder
#

the script probaly goes on the parent on the cylinder

#
  • a rigidbody
toxic ledge
rich adder
#

you can see the warning did print so you are indeed missing rigidbody

rich adder
#

RobotVacuum

toxic ledge
#

let me try to put the cripst agin on it ig

rich adder
toxic ledge
rich adder
# toxic ledge huh?

i mean takes a few seconds to double check but if you have PlayerController nd rigidbody already on RobotVacuum you have an unintended extra PlayerController script somewhere

toxic ledge
#

Well the scrip is not on the cupe

#

Cube

rich adder
toxic ledge
#

No i mean at frist i tought i put the script on the cube

rich adder
#

do you have the PlayerController and Rigidbody on the RobotVacumm

toxic ledge
#

But i didint

toxic ledge
#

But when i remove the rigidbode it work olmost normali

rich adder
toxic ledge
#

The pink cube dosent have it

rich adder
#

You don't need it there either, it has to be on the parent

#

so it moves both + cam

#

its even on the tutorial

#

the cube / cylinder is just a visual

#

they don't need anything

#

unity script nullguards, is just a little wonky but the setup is correct

toxic ledge
#

But the error ses the cylinder dosent have a rigid body

toxic ledge
rich adder
toxic ledge
rich adder
#

brother..

#

why do you have rigidbody and the script on the cylinder

toxic ledge
rich adder
#

the Cylinder is only for visuals / collider (in this case)

toxic ledge
rich adder
#

twice

#

You don't need the script there at all

#

nowhere on the tutorial it says to do that

#

not sure where the miscommunication breaks down here lol I been saying it forever

toxic ledge
rich adder
#

the entire RobotVacuum is the Player

#

the prefab

#

so when they say to put it on the Player, they mean the ROOT. Nowhere does it say anything about putting it on the Cylinder / child object

toxic ledge
#

Maybe when i drag it the scrip it got putted there idk TvT

rocky slate
#

hello

toxic ledge
rich adder
rocky slate
#

anyone can teach me about active ragdolls?

#

like physics n shit

rich adder
toxic ledge
rocky slate
#

tbh i needa learn scripting first

rich adder
rocky slate
#

cause ik nothing

rich adder
#

!learn

radiant voidBOT
rich adder
#

pathways ^

toxic ledge
rich adder
#

we all started there at some point or another

toxic ledge
rich adder
#

the coding isnt really the main focus of this lesson, copy and pasting the code isnt the way to learn coding

#

you can copy and paste but you should at least try to understand what each line does

#

this aint the tutorial for that, better resources for coding are Pinned here

toxic ledge
#

Idk how tho TvT

#

You can ask me half of what i did idk what to sey

rich adder
#

repetition is key

toxic ledge
#

Trust me ik tho i feel so dumb.

#

Idk how to explain it

#

Dhiw hiw i maneg to broke someting agin

#

How i am so down bad that i cant even do as a video ses

rich adder
#

have a little self confidence, putting yourself down isnt a good start

toxic ledge
dapper field
#

I'm trying to implement a save-load system into my game, and jsonutility just doesnt like me i guess?

#

I don't know what's going on. The actual file has the correct number, but then .FromJson just decides it's actually zero

grand snow
#

JSON utility is a bit shit btw

#

Then you are not constrained to unitys serialisation rules

#

You probably already have the unity json.net package in your project!

dapper field
#

Out of sheer curiousity, what serialization rule could possibly be doing this? It's saving correctly, and I made the thing just public float power. Gonna admit I'm copying a tutorial essentially word for word, so I also wanna know if I messed something up somewhere else that might mess me up in that too

verbal dome
#

The SaveData class

grand snow
#

Yes things such as this

dapper field
grand snow
#

And what about that other class?

verbal dome
#

It's super fast too

#

C++ based

#

But yeah for more customization you'd want to use a different package

dapper field
grand snow
grand snow
# dapper field

Looks okay so double check you are reading the correct file text

toxic ledge
#

Man i think i give up

dapper field
grand snow
dapper field
#

And I'm getting the number when it reads the text, it's when i convert from json that it decides it's zero

dapper field
dapper field
verbal dome
#

How was the save file created?

grand snow
dapper field
dapper field
#

its under appdata\locallow\defaultcompany\gamename
whenever I hit save again it still works

gleaming haven
#

[SerializeField] private Light lamp;

why do I get a "Type mismatch" when I drag a PointLight object into this script?

verbal dome
#

Are you dragging a scene object onto a prefab?

gleaming haven
#

no, I have this script on a cube, and I want it to get like a reference to a pointlight

#

so I can enable or disable it

verbal dome
#

So this cube is in the scene and not a prefab?

#

Maybe show a video

gleaming haven
#

I have a cube in a scene
cube -> has this script with the SerializeField
a PointLight object -> also in the scene, and I want to drag this into the SerializeField of the cube

verbal dome
#

And the field immediately says "Type mismatch" after you drag it?

gleaming haven
#

yup

#

is this an incorrect datatype?

verbal dome
#

Did you change the type in the script recently?

verbal dome
#

But changing a field's type might make unity bug out a bit in some situations

#

Try renaming the field or somtehing

gleaming haven
#

I got it
what a stupid mistake
I had a script that was called "Light", so it had the same type and this is why it gave me a mismatch

verbal dome
#

But why would it let you drag it in 🤔

gleaming haven
#

it didn't let me previously, now it does

#

it's working now

verbal dome
#

Ah I thought it was letting you drag it in

gleaming haven
#

now I got a working lightswitch 👍

toxic ledge
solar hill
#

good in what way

verbal dome
#

That onTriggerEnter is cursed

#

-It should be capitalized OnTriggerEnter
-It should take a Collider parameter, not Collectible
-You are destroying yourself, not the other object

toxic ledge
solar hill
#

your ide is probably not set up correctly

toxic ledge
solar hill
#

!ide

radiant voidBOT
toxic ledge
#

Is that a badthing?

solar hill
#

look at the bot message

#

please

naive pawn
#

then click the link that says visual studio code

#

(vs stands for visual studio)

solar hill
toxic ledge
#

I did it and the scrip still dosent work

rich adder
#

it will tell you why your onTriggerEnter method does not do anything

toxic ledge
#

Idk i did exacly whst they sed and it still auto fill the same

rich adder
#

show its configured

#

if you start typing onTrigger even wrong capitalized the IDE will suggest the right one

toxic ledge
naive pawn
#

ah yes, the ai intellicode

#

i'd recommend not using that

rich adder
#

if you press Tab does actually put the lowercase one ?

toxic ledge
#

my head hurts

dapper field
rich adder
#

yeah thats borked

#

just disable it

naive pawn
#

this is what you should be seeing

#

this is intellisense

rich adder
#

or lowercase

toxic ledge
grand snow
#

so be extra sure the data in json actually matches the type you are deserialising into

naive pawn
rich adder
#

or yeah maybe its a seperate setting for intellicode

#

havent checked in a while

naive pawn
rich adder
naive pawn
#

ah i thought you mean googling

rich adder
#

oh yeah should've clarified in VSCode settings

naive pawn
#

i remember intellicode existing before that. does that also apply to intellicode?

#

i guess so, there's no separate intellicode. mb

rich adder
#

I think they deprecated the extension cause it was broken

#

barely worked

#

they merged it all into github copilot iirc

naive pawn
#

oh they rebranded it to inline suggest

toxic ledge
#

now i hage none

rich adder
#

so you dont have unity connected at all

naive pawn
#

you might notve configured your ide properly

toxic ledge
rich adder
#

this page also gives you the If you are experiencing issues

#

very useful.
restarting pc is very important step after getting .net SDK

toxic ledge
#

il try it but my heads feels like it will explode

naive pawn
#

you shouldn't have to restart your pc afaik

rich adder
#

nah PC

naive pawn
#

odd

rich adder
#

I did it recently on a new machine and it worked but kept spewing .net errors even tho dotnet command worked

naive pawn
#

oh is this with the external sdk

#

you only need to restart vscode if you use the .net install tool iirc

rich adder
#

ohh ok never used install tool and the installer for the unity extension always fails

#

restart fixed it.. probably PATH issues

#

tho in cmd it would work but vscode kept saying dotnet not recognized 🤷‍♂️
it was weird cause intellisense itself started working

toxic ledge
#

So i shud delte the studio code editor?

rich adder
toxic ledge
rich adder
#

its easy

#

come back to it with fresh mind

naive pawn
#

this is a help channel, we're here to help

#

if we weren't free (or.. being productive notlikethis) we wouldn't be here

toxic ledge
naive pawn
#

but yes do take breaks

#

rest is important

toxic ledge
rich adder
#

well mind never makes sense tired 😛

naive pawn
#

when i'm procrastinating my source of dopamine is either helping people or scrolling youtube shorts and i prefer the former

rich adder
#

I made the dumbest bugs when coding till 5AM no breaks

#

next day was like " why would i do this.." fixed it in 2 mins

naive pawn
toxic ledge
twin pivot
rich adder
#

no lie

dapper field
# grand snow so be extra sure the data in json actually matches the type you are deserialisin...

I tried deserializing directly into the struct that SaveData has as a field, and it worked.
What's confusing me now is the tutorial I'm following deserializes (using JsonUtility) directly into the SaveData struct, and that automatically assigns the values of the inner struct.

His code:

    public static void Load()
    {
        string saveContent = File.ReadAllText(SaveFileName());
        _saveData = JsonUtility.FromJson<SaveData>(saveContent);
        HandleLoadData();
    }

    private static void HandleLoadData()
    {
        GameManager.Instance.Player.Load(_saveData.PlayerData);
    }

My code:

    public static void Load()
    {
        string saveContent = File.ReadAllText(SaveFileName());
        _saveData.PistolData = JsonUtility.FromJson<PistolSaveData>(saveContent);
        HandleLoadData();
    }

    private static void HandleLoadData()
    {
        GameManager.Instance.Pistol.Load(_saveData.PistolData);
    }
}

Our structs are the same (just different names), so I don't see why I can't do exactly what he's doing. If I can figure out why I can't, I'd rather not have to handle every different object's save data individually in the Load() method

toxic ledge
#

I dont wana stop cus soon is school and i berly neard how to somehow use sound laights and textures

grand snow
#

Json.net can however de serialize into a List/Array directly if your json was [1,2,3]

rich adder
toxic ledge
dapper field
grand snow
#

I dont know because you never showed example json

twin pivot
naive pawn
toxic ledge
dapper field
grand snow
twin pivot
grand snow
#

I will ignore you if you send images of text

toxic ledge
rich adder
#

how will learning tired help

twin pivot
toxic ledge
dapper field
#

(i'm sorry everyone else for the text walls)

twin pivot
#

Might want to use a code service

toxic ledge
#

is this what im supose to have?

twin pivot
rich adder
#

did you look at rest in link

dapper field
#

also if anything in other stuff matters lmk
I don't think it should but I'm not certain

grand snow
#

This json needs to be deserialized as PistolSaveData because thats the object def it matches

toxic ledge
#

brb i make 4th coffe

grand snow
#

This would be de serializable as SaveData:

{
    "PistolData": {
        "gravity": 2.0,
        "power": 10.0,
        "mass": 1.0,
        "roundsPerSecond": 2.0,
        "magazine": 8.0
    }
}
dapper field
# grand snow This json needs to be deserialized as `PistolSaveData` because thats the object ...

I'm following this tutorial
https://youtu.be/1mf730eb5Wo?si=clcji5JNowGaFc5g
From around 4 minutes is where it's relevant
he uses the same save syntax as I do, but he gets it as something he can deserialize as SaveData

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this tutorial Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH

--
In this video I'll show you how to make a complete save and load system from scratch, and I go through several different sc...

▶ Play video
grand snow
#

doesnt matter i wont even watch it

#

What i have said is true

dapper field
#

oh

#

i found it

grand snow
#

I hope now you can see how data can be de serialized from json into an object instance and just recognise where you fucked up

dapper field
#

i had an extra .pistoldata

grand snow
#

there ya go

dapper field
#

im gonna go bang my head against a wall now see you in 4 hours when i'm no longer unconscious
or not idk

#

tysm

toxic ledge
#

Let me wash my face maybe that will help me

queen adder
#

making my first unity game with barely any experience..trying to get my mouse cursor to lock in the middle and be hidden but getting this error:

naive pawn
#

well, do you have the proper using directive?

#

Cursor is defined in UnityEngine

#

ah goddammit

queen adder
naive pawn
#

could you show your code, and where are you getting the error from?

#

!code

radiant voidBOT
queen adder
#
using UnityEngine;

public class CameraController : MonoBehaviour
{

    public float sensitivity = 2f;
    public float xRotation = 0f;

    void Start()
    {
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
    }

    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f , 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        transform.parent.Rotate(Vector3.up * mouseX);
    }
}

#

and for no apparent reason its working now?!! im so sorry 🤦‍♂️

solar hill
#

Did you save the script 🧐

naive pawn
#

probably forgot to save/recompile before

queen adder
#

eh whatever, something worked. thanks for helping anyways haha

solar hill
#

sometimes it happens

toxic ledge
#

hello im back

#

and somehow i think i broke the scipt editor even more

verbal dome
#

Telling us that something is broken without details just wastes our time

toxic ledge
#

how can i fixe my scrip editor?

#

like when i type it dosen out filss etc etc

verbal dome
#

Follow the link you were given

toxic ledge
#

i did

verbal dome
#

So you completed all steps?

#

Usually people say they do but they actually didnt

toxic ledge
#

i put them

#

idk if i did it corectly tho

#

if someone kowns im all ears

rich adder
#

well if you followed all the steps in the link there should be no issues

verbal dome
toxic ledge
verbal dome
#

(So you did not follow the steps)

toxic ledge
#

man still dosnet work what did i do rong

#

do i need this?

solar hill
#

A configured IDE?

#

absouletely

toxic ledge
#

this i mean

#

it didint send for some reson

slender nymph
#

yes you need that. what do you see in the output tab of vs code

toxic ledge
#

still nothing

#

fuuuu

slender nymph
#

show it

toxic ledge
slender nymph
#

show the output tab, which you said you see nothing in

toxic ledge
#

maybe cus im not fluent in english

slender nymph
#

it's the tab in vs code literally labeled "output"

toxic ledge
slender nymph
#

in vs code
is that a screenshot of vs code?

toxic ledge
verbal dome
#

In the top bar

toxic ledge
rich adder
# toxic ledge

so you didn't install the .net sdk as it said on the page

verbal dome
#

Right so did you install .NET SDK or not

#

Jfc

#

Stop saying you did all the steps

#

If you didn't

toxic ledge
#

bro i thought i did TvT

rich adder
#

literally the only reason to restart the pc

toxic ledge
#

sorry..

#

there i think i did it

rich adder
#

install .net sdk , restart PC. There isn't much to it should work right away

toxic ledge
#

bad new it dosent give me what i need

verbal dome
#

Where are you typing that?

#

It only works inside a MonoBehaviour class

rich adder
#

yes please dont crop screenshots too much

#

your brackets look somewhat fucked

toxic ledge
#

so what shud i do.

rich adder
verbal dome
#
public class qwerqwerqwerqwerqwre : MonoBehaviour
{
// Type here
}```
toxic ledge
solar hill
#

dude why are you cropping your screenshots so much...

#

just show us the code

toxic ledge
#

i can berly think

solar hill
#

post the script, we dont care what it litterally looks like inside of the project

#

we need to see the script itself

naive pawn
toxic ledge
naive pawn
#

1 hour of work when you're well-rested is more productive than 5 when you're tired and barely conscious

verbal dome
#

You are missing a } so it doesn't know how to handle it

#

Every { needs a }

toxic ledge
solar hill
#

ok and does it autocomplete now?

toxic ledge
rich adder
#

you just showed us it did

naive pawn
#

have you installed the .net sdk

solar hill
#

are you positive, and i mean absouletely positive, you were following the steps for vs code, and not visual studio?

rich adder
#

you just put it in the wrong part

toxic ledge
solar hill
#

also this, your now deleted screenshot actually showed some autocompletion

naive pawn
#

-# was it text or member autocomplete...

rich adder
#

yes it was configured at least from quick flashed screenshot that appeared, if intellisense is not showing its odd cause it showed before

naive pawn
#

dude really just needs to sleep

verbal dome
#

@toxic ledge It ONLY shows when you are typing it

naive pawn
#

or if you manually trigger it with ctrl+space

verbal dome
#

Well it didn't look like that in your screenshot

toxic ledge
naive pawn
#

yeah that does look configured

#

try ctrl+space

toxic ledge
solar hill
#

did you perhaps disable something in the settings for vs code?

#

or adjust anything

verbal dome
#

They did have some intellicode stuff going on and people suggested to turn it off

#

So maybe

toxic ledge
naive pawn
#

this is gonna be so dumb if they disabled intellisense from me telling them to disable intellicode

solar hill
#

i have a feeling its almost certainly this

rich adder
#

lol

naive pawn
#

you need to sleep

solar hill
#

because fuck normal naming conventions

naive pawn
#

microsoft 🚬

toxic ledge
rich adder
#

it did show OnInitialized attribute earlier in intellisense

solar hill
#

cant wait for vs code to introduce inteliJay their new ai assistant

#

that wont confuse anyone

naive pawn
solar hill
toxic ledge
solar hill
#

that was not a yes or no question

naive pawn
#

which one?

solar hill
#

inb4 both

naive pawn
#

there is no intellicode option - i was mistaken, it was rebranded into a different thing

#

so if you think you disabled intellicode, you probably actually disabled intellisense

solar hill
#

can you no longer disable it?

rich adder
#

intellicode is deprecated on VSCode as an extension

#

only suggestions that appeared were from Github Copilot

#

which is now baked into VSC (sadly)

toxic ledge
#

i checked

grand snow
#

thanks microslop /s

naive pawn
#

@toxic ledge go into your settings and filter for modified options. see if you've disabled intellisense

toxic ledge
#

only think was ai disabel

naive pawn
naive pawn
toxic ledge
#

it outofild but not the the small window

naive pawn
#

no clue what you're talking about at this point

#

are we back to intellicode

#

notlikethis holy shit dude go sleep

#

you are not in any shape to do debugging right now

toxic ledge
#

maybe i shud just leave the server im to dumb for this

naive pawn
#

no, you should sleep

#

you are too tired for this

toxic ledge
#

but if i dont do it it will bug me all night

naive pawn
#

you're not able to think or communicate clearly right now

#

you can rest and come back to do this in 10 minutes, or fight through the tiredness for 4 hours. your choice

toxic ledge
naive pawn
#

no, you need sleep

#

stop hurting yourself

#

if you keep at it you'll just burn out

toxic ledge
naive pawn
#

do you want to make games or not

toxic ledge
#

i do.

naive pawn
#

you will not be able to if you don't rest

#

go rest

#

we cannot help you if you refuse to help yourself first

daring sentinel
toxic ledge
naive pawn
#

breaks are daily or hourly, not monthly

daring sentinel
#

Yeah they're mandatory, during breaks is when stuff starts to actually click

toxic ledge
naive pawn
#

you won't be able to make anything if you don't take care of yourself. going to rest, taking a break, is not time away from the project. it is time for you to prepare for the project

naive pawn
daring sentinel
#

Nah, tbh you're only really dumb or bothering anyone if you're like that toonsouls guy who uses AI for everything

#

but fr please just take a break

naive pawn
#

to be blunt, in the hopes this'll convince you, trying to help you in this sleep-derived state is more of a bother than just seeing you again half a day later

#

we can't really help you in this state.

#

being sleep-deprived itself makes it harder to decide to go rest. so take this chance to let us tell you to go rest. this is a step in solving your issue

toxic ledge
#

fine is just that i ryly want to learn sum that i like find cool

naive pawn
#

and right now you're too tired to learn

#

learning is good

#

forcing yourself to "learn" when you're not able to learn is not good

#

go rest and come back when your mind is refreshed

twin pivot
#

Jesus christ is this guy still awake

toxic ledge
twin pivot
#

Dude go to sleep and try tomorrow

toxic ledge
#

fine.

#

just cus i ryly like chris hes nice

#

or she

naive pawn
#

will you go sleep for me, then

toxic ledge
#

or them

toxic ledge
#

gn

vast matrix
#

How would I make something happen (for example a door opening) when the player is within a certain distance if they press a certain button? Something like OnTriggerEnter but instead of it only happening when the Player enters the trigger it happens only if they are inside the trigger?

#

oh I just found out about OnTriggerStay

feral mango
#

Yo how do u use version control

slender nymph
#

!vc if you want to use unity's version control see the guide linked below. if you want something else, then google how to use git

radiant voidBOT
cosmic dagger
vast matrix
#

Im not understanding how to create randomly spawning items. If someone could please help me understand how to do this it would be greatly appreciated.

vast matrix
solar hill
#

I dont think object pooling is really related to what you want to do

#

How are you deciding which item to spawn, and how are you spawning them?

#

show us your code

radiant voidBOT
cosmic dagger
#

to grab a random item, you need a collection: list, array, etc., of items, then choose a random number (based on the length of the collection), then use that random number as the index of the item to spawn . . .

vast matrix
# solar hill How are you deciding which item to spawn, and how are you spawning them?
using UnityEngine;
using UnityEngine.Pool;
public class PotionSpawner : MonoBehaviour
{
    [SerializeField] private Transform[] spawnPoints;
    [SerializeField] private float timeBetweenSpawns;
    private float timeSinceLastSpawn;

    [SerializeField] private Item_Interact Items;
    private IObjectPool<Item_Interact> ItemPool;

    private void Awake()
    {
        ItemPool = new ObjectPool<Item_Interact>(CreateItem);
    }

    private Item_Interact CreateItem() 
    {
        Item_Interact item = Instantiate(Items);
        item.SetPool(ItemPool);
        return item;
    }

    private void Start()
    {
        
    }

    private void Update()
    {
        if (Time.time > timeSinceLastSpawn)
        {
            // Spawn Items
            ItemPool.Get();
            timeSinceLastSpawn = Time.time + timeBetweenSpawns;
        }
    }``` This is the current code im using.
#

Currently I'm just trying to spawn a singular item then Ill change it into an array

solar hill
dawn wave
#

I have something like entityStats.primary.strength.finalValue = entityStats.primary.strength.baseValue + entityStats.primary.strength.bonusValue;. It would of been tedious to write that for every single possible stat and I wanted to practice using reflection and succeeded in iterating through my EntityStats script, getting its # of fields of a specific type, accessing the nested values within a type ofStat within those specific types, and doing the final = base + bonus; logic. I'm new to C# and wanted to ask if reflection is a "common" way to do something like this or should I of done something else? Maybe a List of Stat objects to foreach() the same final=base+bonus?"

sour fulcrum
#

Reflection is not common period

#

Can’t give full answer to your question rn but just mentioning that

verbal dome
#

Code generation is one alternative, and I guess property bags

#

That goes more into advanced territory though

verbal dome
#

Using multi cursor editing in your IDE might make it less painful to do manually

dawn wave
#

EntityStats.cs has 3 types called "Stat_Primary/Secondary/Resources" and within those three, each have "Stat" fields of varying amounts. "Stat" has a base/bonus/final value float

verbal dome
#

Another way is to have the stats as key-value pairs in a dictionary, iterate over it and add the values together

dawn wave
#

I'll check that out and practice it, thanks. So is reflection something I should probably forget about since there is probably always a more intuitive way to do something I'm trying to implement?

verbal dome
#

In a way reflection is usually the "last resort"

#

It is known for being slow but you can always do the reflection in a loading screen and cache the results

#

So not totally off limits

#

Maybe try different approaches and see what works for you

#

Reflection also has some compatibility issues if you make an IL2CPP build, not sure what tho

dawn wave
#

Yeah it was 8 lines but I'm aware of the overhead that reflection entails. I'm always interested in finding out other ways to do the same thing, especially if it's less lines

verbal dome
#

Oh wait I misread a bit. I was assuming you need to add two different stats together

#

But you are just calculating the finalValue from baseValue + bonusValue

#

Definitely use a List<Stat> for that

dawn wave
#

haha okay

elfin pike
#

i made struct and i need it be nullable so i placed after ?, but now cant access values

verbal dome
#

Can't access values?

#

Show the code + error

elfin pike
# verbal dome Show the code + error

'StatsData?' does not contain a definition for 'timeElapsed' and no accessible extension method 'timeElapsed' accepting a first argument of type 'StatsData?' could be found (are you missing a using directive or an assembly reference?)

verbal dome
#

You need to get the value from it

#

if HasValue -> use Value

elfin pike
#

dont understand what you mean?

verbal dome
#
StatsData? stats = // whatever

if(stats.HasValue)
{
  stats.Value.timeElapsed = // whatever
}```
silent cipher
verbal dome
#

Needs more crabs

silent cipher
#

well i dont cnow hoew to add crabs here

#

actually itahts my biggest problem

#

does someone knows how to hide hiererchy cause i dont need it at all

verbal dome
#

You can close any window if you right click its name > Close tab

silent cipher
#

thanx

crystal hollow
#

using UnityEngine;

public class See : MonoBehaviour
{
// breaking boxes

privat string Tag = "_cardbox";
privat GameObject pl = player;
privat float power = 8f;
privat GemaObject fl = floor;
privat string Tag = "Object1" ;


void Update()
{
    if (Tag("_cardbox") => power, Collision.collision(Tag("Object1"), fl))
        Destroy(Tag("_cardbox"))
        else
            return;
            //If the box falls or hits another object or obstacle, it breaks.
}

}

#

How can I improve or what should I study to improve this code?

rocky slate
#

can anyone send me the best coding learning video / web page

verbal dome
#

What's up with the privat stuff?

frail hawk
#

also you have typo private GemaObject should be GameObject

verbal dome
#

Most of that doesn't make sense

sour fulcrum
rocky slate
#

xdd

verbal dome
#
 if (Tag("_cardbox") => power, Collision.collision(Tag("Object1"), fl))
            Destroy(Tag("_cardbox"))```
🤔
#

I feel like this is from a completely different engine/language

keen dew
#

Trolling?

verbal dome
#

Pretty sure privat is swedish and not C#

frail hawk
rocky slate
#

cheers

crystal hollow
sour fulcrum
#

the code you made is nonsense

#

it does not work

#

its like if my sentence was typed like this

#

typed sentence if was its like this my

frail hawk
#

to me it looks like writing code and praying that it works

naive pawn
#

i mean like, just try pasting that code in and see how many errors you get

#

i count 15

#

i don't think you should look to "improve" that code. that kinda implies it works to begin with

before improving, you need to get something that works first

crystal hollow
#

Okay 😅, then what resources should I study and where should I get information from?

frail hawk
#

first tell us what IDE you are using and if you have intellisense on because it really looks like you wrote this inside notepad

crystal hollow
#

Vsc

#

Yes, there is no auto-complete option for what can be entered, and C# kit doesn't apply since I'm in Russia and I don't use a VPN. Maybe I should download a different IDE?

frail hawk
#

vsc is fine but you need to configure it

#

!IDE

radiant voidBOT
frail hawk
#

but i dont understand the part why C# kit is not being applied

silent cipher
#

actually thats great but...

toxic ledge
#

Hello

fresh oar
#

!learn

radiant voidBOT
distant saddle
#

hey guys , i would like my character to not die on the spike and instead approximately follow the arrow when i press the right button in this situation , is there a name for this situation ? how would you do it ? i was thinking of shrinking the hitbox but it feel like a "solve a problem , create ten more" solution .

sour fulcrum
#

Remove the first two spikes 😄

distant saddle
frail hawk
#

give the 2 spikes a different tag

#

if you are wokring with tags to determine the collision

sour fulcrum
#

Respectfully i think that’s not a great idea