#💻┃code-beginner
1 messages · Page 819 of 1
you'd want to set the min to -50 then, not the max
yes well said, otherwise the newly gained euler angles are 0-360 which are harder to clamp without extra effort
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?
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
guys, how can i change an order in layer of textmeshpro?
ugui or normal tmp?
well, ui -> Text - TextMeshPro
So UGUI. Draw order is the same as all UGUI graphics, based on hierachy order
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.
oh, well. every object in menu is on canvas. i guess it's not good...
Each canvas seperates its children for rendering so using too many prevents batching optimisation
Usually you just need the 1 canvas and maybe a few sub ones for large "popups" or menus
i get it. well, idk why but tmp doesn't show up in game window. only in scene window
Toggle 2d mode in the scene view and check if the text has some crazy Z position
can someone help me with my code?
!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
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.
If true the current world position is maintained while changing the parent transform
If false, the current local position is kept meaning the world position could change
Transforms actually only store local position and that is relative to its parent
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
The short version of it is, "do you want to your object to teleport to the thing you're parenting to, or not"?
can someone help me why my menu is colliding with this and doing this when ive made a build to test it
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.
its meant to look like
Are you using anchors correctly?
i think so
Sorry my explanation did not suffice but understanding how local positions are relative to their parent is critical and should make this very clear
Wow ben 10
fyi the unity inspector always shows local position for transforms
wow that tells me fuck all
go read this: https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/UIBasicLayout.html#anchors
I dont understand what it does when tru and what when false
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
true: unity please change my local position after changing parent to keep my current world position
false: just change parent and THATS IT
what would be a good achor for it cuz im struggling ive done it before but idk @grand snow
The point is to place them where you want the rect transform to "follow" as well as how to resize
I recommend changing your game window resolution to 16:9 or 1080p and then correct your UI layout
You would be better reading the full documentation unity has on UI layout
i am but im confused lol
Change your scale mode to "scale with screen size" and put 1920x1080 as the reference and things should work a lot better
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-CanvasScaler.html
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?
By "exact position" being their world position then correct
Yes its world like where it was in world before being a child
Yes
Extra work is needed to maintain that world position when changing a transforms parent
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.
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
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?
fuck it yes
i sense a miss understanding but close enough
just test yourself if you need to see stuff move 
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
should this effect it
I mean yes it makes sense
cuz its a different scene
What re you making the next Ben 10 game XD?
for Ps2 or Ps5 exclusively?
I remember playing ps2 ben 10
Alien Force if I remember
no im making it cuz i want one but im confuesed why unity is doing that to that scene n shit
@grand snow how do i fix this one
@sage mirage do u know how to fix this
yea pinging random people will get them to help
Your camera needs to have a skybox or solid colour background
Wanna join call really quick?
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
I am not a maniac or serial killer but I prefer call because its better you can share me your screen
YOu can even see who I am XD
thank you so much for helping me, this just doesn't work though, it just works once at the beginning and then it keeps having the same stereo i think
ik ik
i just dont like to in general
ok provide more context then
It would be really nice if you could record your screen using OBS
lemme record a thing one sec
and show exactly what is going on
I was trying it out it works for me just fine. The pan is updated each frame after all.
I added your script to the enemy, put the player as target, the maxstereorange to 10 and the footstepsAudioSource into the audiosource field, and the sound isn't getting emitted from where the enemy is compared to the player
gonna make a new build then i will
The "target" is the audio listener such as your player or main camera
fixed it some how
The audio source still needs to be placed where it physically is in 2d space
exactly, it's updated but I think the logic is wrong, because sometimes when the enemy is on the right, the stereo is negative...
it's at the enemy position, childed to the enemy and its spatial blend is 2D
It's meant to work this way... It's -1 to 1
yea but when the enemy is on the right, it should be positive and the other way around when on the left
if you want, I can send you a video
I think the logic is fine
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
I thought their project was a 3d game no
would that not affect certain things
In 3d we just use what unity provides
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
how?
Put spatial blend to 3d
spatial blending works until the actual volume of whatever you have is so great it straight up overrides any sort of spatial blending
Then it works like real life
if this is the same issue they had yesterday
Oh right so the normal 3d blending is not desired?
yeah
I honestly presumed this was for 2d based on the request haha
i recognized it as the same problem they had yesterday, i so remembered it was indeed 3d
Are the 3d sound settings not sufficient to solve this either?
they said they tried them and it didnt work 
User error?
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
in #🔊┃audio
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$
The solution to this in 3d is more complex as it's based on camera rotation
Im stuck with one issue. I have ScriptableObjects, each has its own id. I have to get object by id
it is
also the stereo panning approach will leave a lot of ambiguity with front and back positions
alright, bet
yea... that's why I really don't know how to do it, I've never really used those Vector3s and math functions tbh
I hate when my problem gets burried by complex problem
buried how ?
its when you msg and doesnt get spotted, because its squashed between other msgs
how do you know it doesn't get spotted its been less than 10 mins.. people do use scroll you know..
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?
i have my own id made with GUID
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 ?
I have folder with SO and IDs. i have to get SO using ID
there are a myriad of ways of doing something, the best suggestion comes in when you explain the problem clearer
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
i had same idea, but it sound like very bad approach
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 ?
i should create class, which stores in dictionary ref and id? can i add or remove if SO is created or removed?
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
Anybody here have worked with IDs?
Ofcourse
how else do we refer to things in a reliable way?
Numerical or string guid/name based ids are what i go with
teach me the way
yesterday I learned about Hash128 if you need some extra speed above storing string / lookup
Dictionary<Hash128, MyThing>
instead of
Dictionary<string, MyThing>
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())
making using GUID, which is made on validation
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
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
Yea then what i said above is what I think
so dictionary is best optionn?
Two things to consider:
The id type
Fast lookup using id
Hash128 isn't serializable. Is there some alternative to strings that can be serialized by Unity?
byte array
you can use the serialization callback interface to perform the conversion
@cosmic cradle
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
you also use dictionary?
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
as collection grows dictionary/hashset usually always faster
its class with dictionary? or you add something extra?
Dictionary<uint, Item> items bam
whatever stores your data after loading can keep them in a dictionary
Maybe i should create SO for this purpose
the data source doesnt matter i guess in this conversation. You can easily parse json.
Though that is an extra step that takes time BUT your data can be updated without a new build
can you nnot crosspost this
not a coding question at all.. if you lookup replace unity armature you will find plenty of videos on this
ive tried man thats why im looking for help
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 ?
i have put effort in it thats why im looking for help jeez no need to be rude
I mean asking someone to do it for you is not putting the effort.. I'm just being blunt
literally put the model in, generate the humanoid armature avatar and put it as child .. use the avatar in the animator
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
no need to put it so rudely man i was just seeing if someone was willing to help
You are asking for someone to just do shit for you
no im not i said help
but you cant save reference in json
i didnt say full on do it
Correct so you would use ids again here too!
instanceId also wouldnt work
Yea... your own custom ids... Did you just forget the whole conversation??
ok stop being so rude
Anyway Ive done this for years, json configuration with ids do as you will
are you like 12 ?
lol
alright this is going in circles.. you're in the wrong channel anyway..
#🔀┃art-asset-workflow at best..
and you got your answers
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...
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
this is really something you have to handle with the place youre distributing your game
and not much to do within unity
unless you are using addressables/assetbundle you need to replace the entire game
so you can with some stuff specifically but in most cases you have to replace
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();
What are you trying to accomplish? Why do you want the binding index?
You're not passing in any path or group, so of course it's going to give you 0
Returns
The first binding on the action matching the given group and/or path or -1 if no binding on the action matches.
I'm trying to add a listener to the action, I'm using Unity Events
Since you provided no parameters it will just map with the first binding
then you are barking up the wrong tree entirely
why are you looking at bindings?
playerInput.actions.FindAction("Spell").performed += SpellListener;
i searched for how to do this exactly and they said that
IDK what you searched or what you were rreading but that's very incorrect
you must be misunderstanding something
To add a listener you subscribe to one of the events
performed, canceled, or started
even tho if it is a unity event?
If you're using Unity Events you don't need to do any of this in code at all
you set it up in the inspector
on the PlayerInput component
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
i know, but i want it to remain assigned even when the scene switches
that's why I want to assign it via code
That has nothing to do with assigning in code vs the inspector
Is the PlayerInput component on a different object than the script that you want to listen to the events?
yes
it is
but I have to
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
thank you!
generate the C# class you can have inputs where you want and skips Player component entirely
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
yea true
Also tricky if there's local multiplayer...
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
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
FindGameObjectWithTag is deprecated
Check the docs for the remaining two:
Oh and I was thinking of it haha they dont write it and I was wondering
im so confused, why is it giving an error yet it works completely fine??
the difference is just plural vs not plural
regenerate project files
You should opt for components instead of tags.
[Deprecated]
and how do i do that? 😅
I mean Yes but this is for the other method
They don't write it on all methods that are deprecated
project settings > external tools > regenerate project files
thanks!
you should be able to use the search bar as well
So, what is going to happen if I am going to use FindGameObjectsWithTag()?
the Unity police will arrest you
deprecated doesn't mean broken
Isn't TMPro old ?
yeah
I mean what deprecated does and is?
wait it is?
I think deprecated is out dated
I thought textmeshpro was now part of unity namespace
it means they're removing it from the API and it won't exist in future versions
maybe
consider googling that
it is
They no longer support probably
Yeah did you install the assert store version or something?
no?
What verison of Unity are you on @potent portal
6000.0.68f1
not exactly
yeah you're doing something weird/wrong
i am following a course from last year so idk
how did you install textmeshpro? It should be in the project by default
Does anyone know how I can get this to fully overwrite the old file instead of just, adding onto it?
oh god it's 2026 already 
So tell me bro
the screen that appears to install it?
what screen 🤔
it works but eventually wont
replaced with something new
that would be append mode, you can specify overwrite mode in the constructor for the streamwriter according to docs
the TMP Importer window
I'll look into that, thanks!
wait you already have that
Ye that was the confusing part, I figured I may of applied it wrong
@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
One says that its not about support and @rich adder says its about support. What is deprecated?
regenerating the project files helped!
wdym suport?
I'm saying deprecated still works until it wont
usually a replacement is already there
deprecated means it's not recommended for use, and it won't be fixed (if issues arise) and will be removed eventually.
it does not mean it's currently unsupported nor currently broken.
I have it to where it prints it, the file saves normal the first time, it's only when I try overwriting it that this happens.
No @naive pawn said its not about support before and you are saying its about support
here
@sage mirage please learn to google. it's a crucial skill. these explain adequately
yeah means they dont actively work on that method anymore
hence " you should switch to yada yada"
you're misunderstanding us both
What to switch?
can you not shitpost ty.
the thing that's deprecated
No Unity is the problem here
they usually give you the alternative right in the deprecated message
because some methods are deprecated and some are not
wtf are you on about
ok?
right so that mean you can use it fine?
What I wanted to say is what s the difference between find with tag and find game object with tag
rigidbody.velocity deprecated
rigidbody.linearVelocity the new method
the name
FindWithTag is shorter? who knows..
It says retrieves the first active game object with tag
in docw
docs
I dont see the FindGameObjectWithTag on docs
XD
yeah its always been that way
this is one of the parts of deprecation
it's not going to be maintained
that includes docs
its been missing in the docs ever since I've used unity tbh
yeah its been that way at least from 2017 from what i recall
that.. isn't particularly strange, especially when there's a well-documented alias
They are actually just the same thing, FindWithTag just calls FindGameObjectWithTag
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..
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 . . .
yeah makes sense being explicit is good
Dam mb i didint kown
no worries, its cheeky humor page explaining why hello generally get ignored.
Can you maybe help me?
👇
: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
as page also says
Just ask the question! 😫
Well maybe yoh ware busy so thats why i asked
If i'm here , I aint that busy xD
plus plenty of people here willing to help
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
holy squint city
https://screenshot.help/
read the error message it usually tells you exactly whats wrong
make sure you followed the tutorial exactly
It ses there is no rigid body but when i add one the cylinder and cube kinda fall of
I did
it probably goes on the entire robot and you might've coded it wrong / put script wrong spot
show the script
Collectible or player?
probably both but mainly whatever script is throwing that error
if you wait for the other person to be free and then that person waits for you to be free then you're never getting help
just ask, if we aren't free then we just won't be in the channel lol
where else am i supposed to go whenever i procastinate on my own projects xD
Idk if is from this tho im still hella new to codeing and all lol
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Ok i feel emberesed now -//-
do i like just post the link or what then..
paste code in one of the links, save and send generated link
feels like a simple fix no? do you have a rigidbody on your cylinder?
you most likely had this print in the console
Debug.LogWarning("PlayerController needs a Rigidbody.");
but hidden by the massive amounts of NullRef
the script probaly goes on the parent on the cylinder
- a rigidbody
wana see what happens if i add one?
you can see the warning did print so you are indeed missing rigidbody
the script + rigidbody probably goes on the parent on the cylinder
RobotVacuum
i think the scrip is on the robovacum and same for the rigidbody
let me try to put the cripst agin on it ig
then you have a copy of it somewhere then
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
cube? no one mentioned cube
No i mean at frist i tought i put the script on the cube
do you have the PlayerController and Rigidbody on the RobotVacumm
But i didint
I did and the pink cube just keeps falling
But when i remove the rigidbode it work olmost normali
because you dont need rigidbody on pink cube why you put it there
I mean on the cylinder
The pink cube dosent have it
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
But the error ses the cylinder dosent have a rigid body
Well is the one that they told me to copy paste
can you show me the inspector for Cylinder
1 sec il show you
the Cylinder is only for visuals / collider (in this case)
You havePlayerController on the the Cylinder...
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
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
Maybe when i drag it the scrip it got putted there idk TvT
hello
Hi
lol very unlikely
theres plenty of resources online on this.
You think to much of me im dumb as briks
like youtube?
tbh i needa learn scripting first
start a bit smaller, or take your time on the lesson theres a lot to unpack
cause ik nothing
then you should start there first, active ragdoll requires a decent knowledge on how to counter forces with rigidbody
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
pathways ^
Idk aready cus i suck ahh at codeing is aready a strugal
thanks
mod this guy?!?!
holy
yes but you only get better when you keep practicing
we all started there at some point or another
Idk but is stress full plus ik il do dumb things like this -//-
ehh we all make those lol as long as you learn from them
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
if you only do something once you're not going to learn much
repetition is key
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
don't rush through it, watch it a couple of times before doing it yourself
have a little self confidence, putting yourself down isnt a good start
Well i have very low self estime so idk TvT
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
JSON utility is a bit shit btw
You are better of using json.net
Then you are not constrained to unitys serialisation rules
You probably already have the unity json.net package in your project!
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
Yes things such as this
And what about that other class?
Pretty simple thing to do, wouldn't call JSONUtility "shit" for that
It's super fast too
C++ based
But yeah for more customization you'd want to use a different package
Looks okay so double check you are reading the correct file text
Man i think i give up
I'm using a helper method to get me the file, so the save and load functions should be pointing to the same place I think
Use a debugger to verify the process
And I'm getting the number when it reads the text, it's when i convert from json that it decides it's zero
brb pulling up google on what that is lo
i think i'm doing that with the debug.logs. Or did I misunderstand?
How was the save file created?
That works but debugging let's you over see the whole process in more detail
The save made it when I first ran it without it created
its under appdata\locallow\defaultcompany\gamename
whenever I hit save again it still works
[SerializeField] private Light lamp;
why do I get a "Type mismatch" when I drag a PointLight object into this script?
Are you dragging a scene object onto a prefab?
you're dragging into a prefab ?
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
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
And the field immediately says "Type mismatch" after you drag it?
Did you change the type in the script recently?
If it lets you drag it in then it should be the correct type
But changing a field's type might make unity bug out a bit in some situations
Try renaming the field or somtehing
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
But why would it let you drag it in 🤔
Ah I thought it was letting you drag it in
now I got a working lightswitch 👍
is this script good? https://paste.ofcode.org/qeKE9AumBCLuEPLkefPaLW
good in what way
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
Like made cus when i run it it dosent destail the thing so i wanted to ask if i did something rong
your ide is probably not set up correctly
Then what shud i do?
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
calc is short for
I did it and the scrip still dosent work
well yeah because you're using the wrong method hence the suggestion to have a properly configured IDE
it will tell you why your onTriggerEnter method does not do anything
Idk i did exacly whst they sed and it still auto fill the same
doubt it
show its configured
if you start typing onTrigger even wrong capitalized the IDE will suggest the right one
that seems to be some weird intellicode
if you press Tab does actually put the lowercase one ?
my head hurts
Tried json.net. The exact same thing happens.
Also I can't figure out how the debugger is supposed to help me here, so now I feel like I'm just back at square zero
or lowercase
idk how
Its to check the data you read from disk and then send to be parsed.
If a value is not read im going to presume the field names dont match and you somehow missed this
so be extra sure the data in json actually matches the type you are deserialising into
settings > search "intellicode" > uncheck the checkbox
i think you can just search disable AI
or yeah maybe its a seperate setting for intellicode
havent checked in a while
i think that would be too broad
idk i got this
ah i thought you mean googling
oh yeah should've clarified in VSCode settings
i remember intellicode existing before that. does that also apply to intellicode?
i guess so, there's no separate intellicode. mb
I think they deprecated the extension cause it was broken
barely worked
they merged it all into github copilot iirc
oh they rebranded it to inline suggest
now i hage none
you have an error there, its probably important
so you dont have unity connected at all
you might notve configured your ide properly

If your IDE isn't providing autocomplete suggestions or underlining errors in red, then it needs to be configured.
this page also gives you the If you are experiencing issues
very useful.
restarting pc is very important step after getting .net SDK
il try it but my heads feels like it will explode
do you mean restarting vscode
you shouldn't have to restart your pc afaik
nah PC
odd
I did it recently on a new machine and it worked but kept spewing .net errors even tho dotnet command worked
oh is this with the external sdk
you only need to restart vscode if you use the .net install tool iirc
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
So i shud delte the studio code editor?
no not at all..nowhere does it say that..
Idk man im fr tierd and im feeling like im bother the chat somehow
take a break
its easy
come back to it with fresh mind
this is a help channel, we're here to help
if we weren't free (or.. being productive
) we wouldn't be here
If i take a il stop cus is 21 here
Idk is just my brain that ses im bothering
well mind never makes sense tired 😛
when i'm procrastinating my source of dopamine is either helping people or scrolling youtube shorts and i prefer the former
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
-# i say as i'm scrolling yt shorts right now...
Idk i atarted at like 10 am whit 2 breaks ig
Devs going thru 50 different side quests just to avoid adding to the main system be like
no lie
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
I dont wana stop cus soon is school and i berly neard how to somehow use sound laights and textures
The type you give to de serialize has to match. Meaning the json needs to be an object that contains the same field names
Json.net can however de serialize into a List/Array directly if your json was [1,2,3]
the computer / project isnt going anywhere lol
But my adhd barin will
so is what I'm serializing not the struct that is the field? (The format looks like {"name":value,"name2":value}
I dont know because you never showed example json
My guy go sleep and try tomorrow i can barely understand what ur saying
you can't just call me out like that bro
1 sec let me drink my 3th coffe
what do i need to show u
json as text and classes as text
Dw im also on here to avoid adding more content
I will ignore you if you send images of text
What i meant is that i dont wana stop becas school starts soon and i didint learn enything for unity
how will learning tired help
When learning code the first curve is usually the most difficult so its understandable if you take more than a day
Dw i have coffe
(i'm sorry everyone else for the text walls)
Might want to use a code service
is this what im supose to have?
That looks good
yes thats part of it
did you look at rest in link
also if anything in other stuff matters lmk
I don't think it should but I'm not certain
This json needs to be deserialized as PistolSaveData because thats the object def it matches
This would be de serializable as SaveData:
{
"PistolData": {
"gravity": 2.0,
"power": 10.0,
"mass": 1.0,
"roundsPerSecond": 2.0,
"magazine": 8.0
}
}
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...
oh i just skipped ahead like 30 seconds and it does look like that
..now why is mine not doing that i have no idea
oh
i found it
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
i had an extra .pistoldata
there ya go
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
Well from there i got those 2
Let me wash my face maybe that will help me
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:
well, do you have the proper using directive?
Cursor is defined in UnityEngine
ah goddammit
please do not crosspost.
yeah my fault, sorry
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
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 🤦♂️
Did you save the script 🧐
probably forgot to save/recompile before
yeah i did i tried a few different iterations lol
eh whatever, something worked. thanks for helping anyways haha
maybe it didnt recompile properly
sometimes it happens
You should ask actual questions if you need help
Telling us that something is broken without details just wastes our time
Follow the link you were given
i did
i dowloded them
i put them
idk if i did it corectly tho
if someone kowns im all ears
well if you followed all the steps in the link there should be no issues
If your IDE isn't providing autocomplete suggestions or underlining errors in red, then it needs to be configured.
Did you do the "If you are experiencing issues" steps...?
1 sec ima try restarting laptop
(So you did not follow the steps)
now i did
man still dosnet work what did i do rong
do i need this?
yes you need that. what do you see in the output tab of vs code
show it
show the output tab, which you said you see nothing in
idk what is that even
maybe cus im not fluent in english
it's the tab in vs code literally labeled "output"
this?
in vs code
is that a screenshot of vs code?
this?
so you didn't install the .net sdk as it said on the page
Right so did you install .NET SDK or not
Jfc
Stop saying you did all the steps
If you didn't
bro i thought i did TvT
literally the only reason to restart the pc
install .net sdk , restart PC. There isn't much to it should work right away
thats what im checking rn
bad new it dosent give me what i need
show what the file looks like and where you typing this ?
public class qwerqwerqwerqwerqwre : MonoBehaviour
{
// Type here
}```
suboptimal class name
i can berly think
post the script, we dont care what it litterally looks like inside of the project
we need to see the script itself
go rest bro
1 hour of work when you're well-rested is more productive than 5 when you're tired and barely conscious
ok and does it autocomplete now?
no
you just showed us it did
have you installed the .net sdk
are you positive, and i mean absouletely positive, you were following the steps for vs code, and not visual studio?
you just put it in the wrong part
yes
also this, your now deleted screenshot actually showed some autocompletion
-# was it text or member autocomplete...
yes it was configured at least from quick flashed screenshot that appeared, if intellisense is not showing its odd cause it showed before
dude really just needs to sleep
@toxic ledge It ONLY shows when you are typing it
i am ;/
or if you manually trigger it with ctrl+space
Well it didn't look like that in your screenshot
no suggestions se
They did have some intellicode stuff going on and people suggested to turn it off
So maybe
only thing i did was i but visual code at preferens or whatever
this is gonna be so dumb if they disabled intellisense from me telling them to disable intellicode
i have a feeling its almost certainly this
lol
dude you are not being coherent
you need to sleep
because fuck normal naming conventions
microsoft 🚬
im not what?
it did show OnInitialized attribute earlier in intellisense
cant wait for vs code to introduce inteliJay their new ai assistant
that wont confuse anyone
did you disable intellisense or intellicode earlier?
yes cus i think chris or nev told me
that was not a yes or no question
which one?
inb4 both
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
wait what lol
can you no longer disable it?
intellicode is deprecated on VSCode as an extension
only suggestions that appeared were from Github Copilot
which is now baked into VSC (sadly)
thanks microslop /s
@toxic ledge go into your settings and filter for modified options. see if you've disabled intellisense
only think was ai disabel
this is not what we're talking about at all
you can, it's just under a different name (inline suggestions)

it outofild but not the the small window
no clue what you're talking about at this point
are we back to intellicode
holy shit dude go sleep
you are not in any shape to do debugging right now
when i look for it show me only 2 options
maybe i shud just leave the server im to dumb for this
but if i dont do it it will bug me all night
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
i just need a 5th cofee maybe
trust me frend i hate my self so i dont mind
do you want to make games or not
i do.
you will not be able to if you don't rest
go rest
we cannot help you if you refuse to help yourself first
Dude are you trying to have a heart attack? Take a break bro
i did like a week ago
breaks are daily or hourly, not monthly
Yeah they're mandatory, during breaks is when stuff starts to actually click
i dont refuse it yall are super nice and cool i just idk i dont wana make yall think im a guiter or dumb cus aready i feel like im bothering..
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
you not resting is refusing help
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
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
fine is just that i ryly want to learn sum that i like find cool
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
Jesus christ is this guy still awake
yep
Dude go to sleep and try tomorrow
will you go sleep for me, then
or them
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
Yo how do u use version control
!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
Unity Version Control
Git
Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.
if they enter the trigger, then they are inside. when they exit the trigger, they are outside of it. you can use those as well instead of constantly checking on OnTriggerStay . . .
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.
what have you tried?
I've tried object pooling and instantiate, but it's not giving me the result that I want.
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
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
well both of those are for spawning an object. do you have anything for the randomization?
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 . . .
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
right, but where is your actual spawning logic?
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?"
Reflection is not common period
Can’t give full answer to your question rn but just mentioning that
Code generation is one alternative, and I guess property bags
That goes more into advanced territory though
How many of these variables does EntityStats have?
Using multi cursor editing in your IDE might make it less painful to do manually
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
Another way is to have the stats as key-value pairs in a dictionary, iterate over it and add the values together
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?
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
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
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
haha okay
i made struct and i need it be nullable so i placed after ?, but now cant access values
Wdym exactly
Can't access values?
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?)
dont understand what you mean?
StatsData? stats = // whatever
if(stats.HasValue)
{
stats.Value.timeElapsed = // whatever
}```
loook
Needs more crabs
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
You can close any window if you right click its name > Close tab
thanx
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?
can anyone send me the best coding learning video / web page
is that ai generated?
What's up with the privat stuff?
also you have typo private GemaObject should be GameObject
Most of that doesn't make sense
making code that compiles
xdd
if (Tag("_cardbox") => power, Collision.collision(Tag("Object1"), fl))
Destroy(Tag("_cardbox"))```
🤔
I feel like this is from a completely different engine/language
Trolling?
Pretty sure privat is swedish and not C#
the term best can not be answered easily but this might be a good start
cheers
What?
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
to me it looks like writing code and praying that it works
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
Okay 😅, then what resources should I study and where should I get information from?
first tell us what IDE you are using and if you have intellisense on because it really looks like you wrote this inside notepad
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?
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
but i dont understand the part why C# kit is not being applied
actually thats great but...
Hello
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
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 .
Remove the first two spikes 😄
i was thinking about that , but my character has a lot of horizontal speed (my game need that) so it can take the spikes after that. And it feels like putting plaster on a wooden leg.
give the 2 spikes a different tag
if you are wokring with tags to determine the collision
Respectfully i think that’s not a great idea