#💻┃code-beginner
1 messages · Page 376 of 1
wait. it's a public array. So the inspector value will be leading
is there a reason it's public ?
Uh, not really
then make it private
The TMP_Text needs to be public, frases does not
you'll need to reassign the TMP_Text in the inspector
did you actually assign it
I think I didn't
I made this with a friend that understands more of Unity than me during night
Im getting started into unity
why is it not letting me click a button from the ui? it worked on the scene i created it, but not now in a completely new scene
you need Event System in new scene
EventSystem missing?
for some reason, when i rotate my camera, only the camera rotates, how can i make it so the player rotates along with the camera aswell?
https://hastebin.com/share/ovehumuxer.csharp - My player movement script if you wanted to take a look at it :)
tysm worked
your player should be rotating and the camera with it, not the otherway around
how could i fix this?
do the thing I just said
Sometimes i dont even know where to start. It dosent set IsGrounded to true
have you tried starting by debugging ?
also why are you doing a FindByType then a GetComponent on the same component
what?
how exactly does Getting component on an already grabbed component of the same type "looks clean"
I mean don't just randomly put stuff there 🤷♂️
I made sense while making the script
well the GetComponent isn't needed if you already find by Type
I am trying to add post proccesing effects to my game but they do not show up on screen. what do i do to fix it?
@lethal bolt anyway have you check if this script/function is even running ?
this is a coding channel, what question do you have about coding?
can someone explain to me why is drag like that? https://gdl.space/hajijorodi.cs
please use links for large !code
Posting code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
mb
did you check the grounded var
if you are using Unity 2022 you can use the Analysis window for Physics Debug, find the Spherecast and enable Casts
Yes and i found out the problem 👍
what was the problem?
Or i dont really know what the problem was but i simplified the script
oh so the thing I told you was unnecessary turned out to cause a problem, what a coincidence
that or you forgot to use a Rigidbody lol
holy shit this helps a lot ❤️
Lol, no.
It was the "Unnecessary" part lol
so glad unity has added it 😅 took so many versions to get something out the box
yea
whata.whata coincidence 🫣
waddayakno
thats a sphere btw
gotta fix this door script now :D, use interfaces and enums
hah yeah its in hell
no sir.. that is a line segment.. and some other ray chilling in there i think
I'm surprised you didn't make a door asset for assetstore yet
spammy
wanna see something ugly?
sure, is it my code from years ago
atleast once
at least
i got this, i can make this 10 lines long, max
Hey at least you had an inventory, i just crammed it all my monolith player class
i didnt wanna screw guy over like that
he'd definitely woulda came bcak w/ problems
atleast my snippet can atleast be scaled a little bit 🤏
you ever get paralysis by analysis cause so many ways to do something 😛
You could make it without enum tbh
ints and index
just match Scriptable Objects
oh no.. im avoiding those
😮
but a key can be an asset you drag n drop into the door slot
so you wont have to create a new enum for new key type / door type
some can have 3 keys
you missing out Scriptable Objects are goated for this
well yeah you need to split those into structs, at least I would
Hey all! I am currently working on a cellular automata liquid script and am trying to create a "new liquid" on the tilemap grid, so essentially trying to align a gameobject to a tilemap using the "WorldToCell" parameter on the vector3. However it seems to be 0.5 off on both axis from the tilemap it is referencing, if anyone has any idea as to why the debug rays are showing as they should be however both the collider attached and the sprite are off-centered while the "offset" of the box collider says (0, 0) any help would be amazing! Below is the example of the gameobject offcentered.
u think?
i dont see how structs would be helpful for all the playercontroller code
newWater.transform.position = blockTilemap.WorldToCell(new Vector3(transform.position.x + direction.x, transform.position.y + direction.y, transform.position.z));
but still I think a SO key door system can be pretty cool, I might just make it a free asset rq 😛
you can have like doors that have specific "Recipe" of "keys"
looks correct to me
cell positions are at the corners
unless i misunderstood what you're asking
you prob want to CellCenter
or w/e is called
well the collider highlighted in the image is supposed to be aligned with the red lines.
Oh that might be why, I'll try that, thanks!
@/navarone all errors are gone!
well why aren't you using the value 😛
thanks :)))
nicee. you fixed the code editor though ?
its a WIP and that variable is nested quite happily in the rest of that script
yup downloaded the community one ahahah much better
i was missing out damn
i guess its a good thing,, its like a todo notification
worked perfectly, thanks!
indeed its a more mature application, plus its a real IDE
this code just says if the player is in trigger and you click E, then set gotGas to true, the player is in trigger because the bool says so, but when i click E it dosent set gotGas to true
what will take more processing power?
1. bool test = BoolReturnMethod() in Awake()
then
void Update(){
if(test{
Debug.Log("Bool");
}
}
or
2. void Update(){
if(BoolReturnMethod(){
Debug.Log("Bool");
}
}
obviously 2.
i just realized
You should look up the docs for the other OnTrigger methods
Enter is only true for a single frame, and never again until after Exit is called and the collider reenters the trigger
that is because that is not what that code says or does
wdym
what dont it say
oh nvrm the ontriggerstay thing worked
it does not say 'this code just says if the player is in trigger and you click E'
you are mixing up one time event methods with update(). Your Input... line is being checked in the frame of your trigger has been entered. if you are as fast as the physics engine and hit the button within that frame, it will work, but thats not what you want. Obviously you should look into the basic tutorials on learn.unity.com for example to get, what the engine is actually doing, when and how often its executing its builtin methods etc etc
How would set up an object to have a trigger and still be solid?
And how would I have the trigger only detect specific objects (like a bullet for example)
Those are contradictory goals
Triggers, by definition, are not solid
Have a non-trigger collider as well.
Validate which object in OnTriggerEnter before doing anything. Using tags, layers, or component checks
Alr thank you
hi everyone so i have a problem that i don't know how can i do
is about saving the selected button
like when you select monochrome and you leave the game
and when you open the game monochrome button is still selected
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
this isn't really saving a selected button
you just need to save a value, like a number or a string
you can use PlayerPrefs to store small amounts of data
What does clicking these buttons do in your code?
i tried that but it didn't work for me or maybe i didn't do it right
for example
it comes with default
when you click monochrome it changes color to blue and default changes to white
i made it work
that's which UI button is currently selected -- but that doesn't really correspond to which option is picked
but the problem is that idk how to make saving
it's just which button will be pressed if you hit enter
You should use the Toggle component
You can put all of them into a Toggle Group
watch the video to understand what im talking about
The only annoying thing is that you'll need to add a separate graphic for when the toggle is checked
ArgumentException: Input Button No Control is not setup.
To change the input settings use: Edit -> Settings -> Input
can anyone help with this please.
also im using buttons
not a toggle
Yes. That's why I suggested switching to using toggles.
the "selected" color is just telling you that you've got that Selectable object selected
like, for keyboard navigation
You could just change the actual color of the text, I suppose
When you click a button, reset all of their colors to white, then color the one you clicked blue
When you start the game, look at the saved setting and use that to decide which button to color
i used the same text to change color
show me your code; i need to see what you're actually doing here
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
ah, okay, so you are already changing the actual text color
I thought that was just the color of a selected button; my bad
Anyway, I would suggest rearranging your code
Create a function that reads the player pref string and sets the button colors
Make DefaultButton/etc. do two things:
- set the playerpref string
- call the new function
When the game starts, call that new function
the new function can also set DefaultMode/MonochromeMode/etc. based on the string
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
i used this to make the save
but idk if i did it wrong
Maybe describe how, why and when the error is generated.
its on startup but ive just figured it out, the controls are missing from the input manager
Hi, would like some advice for starting a project that is very UI heavy. 2D puzzle
The advice is: don't make it ui heavy.
Seems more like a statement without any point than advice
Nope
Why does it have to be ui heavy?
Well, your question didn't provide any context either
hi the death animation endlessly repeats in my game and im following a tutorial that has a box that is can/cant transition to self but i dont see the box on my end. I was wondering how i could get it or if someone could help me correct a destroy command?
Well, why does it transition into self in the first place? That doesn't seem correct.
Plenty of context while staying open-ended. Remember we are in #💻┃code-beginner too, this is adds to the context as well. I don't see the advantage of writing advice that doesn't serve to help, either that or you maybe you don't know how to. Leaning on the former. Wastes both of our times
Please don't
Just provide the context
well i tried setting it as a trigger but that didnt work so it is currently a bool which i think is the reason it keeps repeating?
Why is it ui heavy. If you don't want to answer, then you should not waste the time of others.
It is unanswerable until we know the extent of the ui, the answers will be different in different circumstances
But you could google the canvas optimization guide from unity yourself if you want generics
Can you explain why it needs to be ui heavy? Are you planning to make the main gameplay elements with ui?
I have a raycast system where if the raycast is hitting a certain tagged object, it set a boolean to true of false depending on if its hitting it or not, but no matter if the raycast is hitting the enemy or not, the boolian will stay at false
A trigger should work exactly like a bool, just one time. If that didn't work, you should debug it instead of changing to an incorrect solution. But also maybe consider why it can transition into itself. Are you using "from any state" or something?
Didn't come here to argue, came here to get advice. It would be UI heavy since I wanted it to be a puzzle game which is all themed inside a computer (OS). There are no planned interactions outside of the computer. I guess a good example would be something like Home Safety Hotline or Space Warlord Organ Trading Simulator.
It doesn't NEED to be ui though. Most puzzle games would not be.
The best way to deal with this would be to NOT make it ui, so that it is more performant
If you're pointing and clicking around a computer then UI components make sense
But as I said, unity has a canvas optimization guide
in that case I'm not sure there's any specific advice, really
Yep, the whole thing is UI. I wanted to go for Unity since I have experience in this engine and I would like to play with the shaders (Like an old CRT filter and such)
beyond deactivating things you aren't using or splitting into multiple canvases
Right. Well, that's the kind of context that you should have provided at the beginning. This kinds of game are perhaps worth building entirely with ui.
I guess I'm not sure what kind of advice you're looking for
Weirdly people were very quick to say not to do it. Considering other engines actually
you've got a very broad subject
This is the guide I was talking about
ohh ok so it goes entry-> idle->death and the idle is not animated. i didnt use the any state block though.
Does the death state have any transitions out of it?
no it does not
is that the issue LMAOO
thats my bad then thanks
Then it shouldn't be transitioning into itself? Is it looping perhaps?
Make sure the animation is not set to looping.
Well, if other engines deal with UI centric games better, then I could go and use those. Also considering the architecture and how UI is based around Unity events, maybe it would be best to use Unity events other the kinds to compliment it
Also if the engine comes packed with things, such as physics, will it affect file size or performance even if I don't use that feature?
file size, yes, but it's not a massive baseline
you're not spending 3GB on engine code
omg yes that was it thank you! "loop time" was selected, i left it checked bc i thought thats what the guy had in the video but i must have missed it :)
and physics updates with no physics objects are going to be extremely cheap
Thanks very useful
Is there a way to strip it down?
I know there is an extesnions feature
And some stuff is packed into there
no, and I would focus more on making your game than trying to slice off every last kilobyte of engine code
Yea true, but hopefully you understand why I ask these questions
I have a piece of code in my game thats not working, it supposed to set a boolian active when a ray is hitting a enemy, but the boolian constantly stays deactivated, no matter if im looking at the enemy or not, heres my code for it: if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out RaycastHit hitinfo, 20f))
{
if (hitinfo.transform.CompareTag("Enemy")) {
IfLookingAtEnemy = true;
} else {IfLookingAtEnemy = false;}
So UI affects performance more than physical gameobjects?
UI is game objects -- it's just that you're using UI renderers instead of, say, MeshRenderer
The cost of re-drawing the UI grows with the amount of UI renderers you have
which is true for basically everything, really
Okay, correction then, UI over sprites
Not necessarily. I imagined something like portal or myst immediately
I was thinking of a sliding tile puzzle game lol
Why can't I put a thumbs up? Weird lol
You should use the profiler to analyze how long it takes to re-draw your UI. If it starts becoming an issue, you can look at splitting into smaller canvases
I use one huge-ass canvas for my game's entire menu
Yea, sorry, I should make it clearer next time
But I also deactivate menu screens that aren't currently in use
there are 291 game objects in my main menu, and that's before I instantiate any sub-menus (like individual settings screens)
I think what dlich and I were thinking at first was the common trap people fall into, thinking ALL 2d games make sense as ui
Like a 2d platformer as entirely canvas based
It comes up more often than I would have thought before helping here
I have always done this too, seems the best way. I can imagine a HUD and Menu canvas being separate, but not sure what else can be separated after that?
Oh lol... I admit I did not think of that
I'm not sure there's a big difference between:
- Canvas
- Huge blob of UI elements (activated)
- Huge blob of UI elements (deactivated)
- Huge blob of UI elements (deactivated)
- Huge blob of UI elements (deactivated)
and
- Canvas
- Canvas (deactivated)
- Canvas (deactivated)
- Canvas (deactivated)
Multiple canvases will be relevant if you have several distinct UI areas
obviously "HUD" and "Menu" is a common split
but think about an RTS
Oh
UI is a separate system
Oh
you can have the minimap, the unit info panel, the top bar
Didn’t know that
I have a car with wheel colliders, the car's mass is 2500 and the wheels have a mass of 20. The trunk is supposed to hold the wood that the player collects which are rigidbodies weighing up to 500 mass EACH. For some reason the heavy rigidbodys cause the car to start floating and the suspension to up to max, how do I fix this?
Hmm, well Fen, for my case I'm imagining each "window" inside this computer's fictional OS to be a canvas... maybe a bad idea, idk
Since you can "minimise" them
that sounds reasonable
windows don't really interact with each other
especially once you get into automatic layout
each window is totally independent
putting a huge text component in one window won't make another window grow or rearrange itself
Try debugging things. Add a debug inside the raycast if block and see if it prints.
Hi all. I am more of an XR designer than a developer, so working with code is not my strong suit. Sorry if this isn't the right channel for Unity error troubleshooting, but does anyone know what this error means and how to fix it? Originally, I thought it was because I forgot to switch the build settings back to "windows, mac, linux". It seemed to have solved the problem the first time, but it's back to causing problems on play mode and showing the same error message.
An index in one of your scripts is greater than the size of the array
Can we see the code
When I click on the error, this is the line of code it takes me to.
Off topic to programming but just wanna say, I tried reacting to your messages a second ago and it wasn't working, it kept shaking and removing it. So I looked it up and just realised that it means the person blocks you. That is so funny and stupid that Discord has such an anti-feature, that allows you to test if someone "privately" and "anonymously" blocks someone. Terrible breach of privacy, could've been fixed by not showing the reaction to the user and but still to others instead.
Anyway, thanks to those you helped, also sorry for not being clearer before, I didnt think of people using Canvas like Sprites and other crazy things. Sorry to @teal viper @summer stump and still appreciate the efforts to help
Debug the lenth of the list (array?) and index
What’s m_views
I'm not sure if you mean me. But I have not blocked you
But either way, no worries
Look at aethenosity man, so inspirational
I'm not blocking you, so no clue why you can't react.
Before, I tried reacting and it wasn't letting me. I looked it up and it says that. Could've been glitched but I just assumed I pissed you off (I literally block people like that so understandable if so). But yea, maybe a glitch or whatever, still what a grand discovery, makes me think how many people realised I blocked them
I have had that happen before. Very odd
When I look it up, it says materialized view? idk
And I tried that, but I don't see anything that sticks out. Maybe I'm not debugging correctly. I'm guessing it has to do with one of the materials maybe?
Well what values did the log say?
!code
Posting code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
Does anyone know the problem with this code?
The error is: NullReferenceException: Object reference not set to an instance of an object
Can you show the complete error?
projectileGun is null
How do i set it?
Preferably in the inspector
Does the instance need to be a prefab?
Or the gameobject with the script in it
Oh i got it!
It needed to be the instance with the script i was referencing
Is this possible to do in a reference?
Is that possible or do i have to divide it into one?
Or 3 parts
sorry to ask, but do you know what i could do to make the player rotate and the camera with it?
@ivory bobcat How can i get the true or false statement of the other script to bring it into this reference?
I want it to change the statement to tell if i can shoot or not. How do i get it from my weapon script and store it here?
Can someone help me with my script?
Im trying to get a true or false input from another script using references.
Drag and drop (serialized references) if you can
You really should just stop and do the learn.unity.com site I keep linking though. It goes over all the basics like this. You would be up to speed in a few days and have a broad foundation to build from
this is for a 2d game
I wasn't sure how to look that up, but after doing some more digging, I discovered that others were having a similar issue! I found a workaround on this page. https://forum.unity.com/threads/xrpass-getviewport-exceptions-in-editor.1577916/
Unity Forum
Hello, I played around with the VR Core Template in Unity 2022.3.23 + .24. After a short time, like going three times into playmode and clicking on...
did you parent the camera to the player?
hello i was wondering if someone could help, the enemy death animation is played and then i want the enemy to go away so i used a destroy(obj) but now when i attack the enemy nothing happens (neither death animation or destroy(obj)
this is the block of code
void Update()
{
if (health <= 0)
{
anim.SetBool("isDead", true);
Debug.Log("Enemy is dead");
Destroy(anim);
}
}
With the Destroy(anim); line commented out the script works and upon attack the animation goes off
no, the camera is parented to an empty game object called "orientation", i tried parenting it to the player object and still no result
and is orientation child of player ?
yes, this is what my player hierarchy looks like
so are you rotating Player/Player Controller?
btw this only destroys the animator component
oh ok so what is the word i would use for the whole object?
every script on a gameobject is a Component
https://docs.unity3d.com/ScriptReference/Component-gameObject.html
ohhh so game object ok ty
i have another question 
i have an attack point which currently uses overlap circle to show when the weapon has hit the enemy. The weapon is kind of like a rope, like wonderwoman lasso, so it shoots out. is there a way i could have the circle made into a polygon that can be shaped around it or move with the rope?
i was looking into this https://docs.unity3d.com/ScriptReference/Physics2D.OverlapCollider.html as well
or is there a way to make a polygon collider 2d that then is used as the attack point but it doesnt react to physics so it can pass into/thru the enemy
can anyone help me with something quick
I am very new to unity and my elephant is floating and i dont know why
there is a sphere mesh collider that is nowhere to be found in the inspector but it's there
i used the instructions from this video https://www.youtube.com/watch?v=1uW-GbHrtQc
Walk, Run, Jump and Sprint! Easily customizable!
A very simple player movement script that will get you started on your 3d project. Code is pinned in comments.
3D, First person (easy change to third person).
Sub for more :)
weird, cant tell much from your picture but I think the sphere collider might be in the camera? if its not check all the childs
its not in the camera and the elephant is the only child
if it appears only when PLayer is selected check PLayer, playyyy and Main Camera
Sphere collider
But when I disable all of the components it's still there
huh I guess try restarting Unity?
its impossible for a sphere collider to be visible if there isnt a component of it in there
think again
ill try restarting
still there
Could it be in the script somehow? i just copied and pasted it
and it's not in PLayer
oh hey
try removing Character controller
even if its disabled its collider is still visible
"Can't remove CharacterController because PlayerMovement (Script) depends on it"
The CharacterController will look like a sphere if you set the height to 0
Also yeah looks like your script has [RequireComponent(typeof(CharacterController))]
Ye, that's my best bet.

hi does anyone know why i cant resize this overlap circle?
code:
{
Collider2D[] enemy = Physics2D.OverlapCircleAll(attackPoint.transform.position, radius, enemies);
foreach (Collider2D enemyGameobject in enemy)
{
Debug.Log("Hit enemy");
enemyGameobject.GetComponent<EnemyHealth>().health -= damage;
}
}
im able to move it around on x/y but the scaling doesn't seem to do anything?
wdym by "scaling"?
OverlapCircle uses whatever radius you give it
in this case, the radius variable
oh hmm the radius is what im trying to modify
well how are you modifying it
unity transform under inspector
Transform doesn't have a radius field
so idk what you're talking about
Show full !code
Posting code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
scaling the transform is not going to affect this radius variable.
only changing that variable will change it
If you want to change radius, change radius
So, radius does not change in code, so changing it in the inspector will change the value of it.
oh interesting i swear it used to work tho and in the tutorial i used it worked there as well
The Transform scale is completely unrelated
what you are decribing makes no sense whatsoever
sorry
something was different when it worked
maybe code that actually multiplied the Transform scale by the radius
There's nothing to apologize for
I promise it did not work like that in the tutorial unless it READ from the transform and used that in the radius
Ah, basically what praetor said.
And yeah, nothing wrong with learning
completely unrelated seeing as you resolved your issue but helpful to know regardless; do you know about [SerializeField]?
okok this was totally my mistake then i was trying to adjust the x and y values seperately but the radius control is within the actual attack script
no i dont know at all
I was hoping i could just change it to this (and added width and height float var)
Collider2D[] enemy = Physics2D.OverlapBoxAll(attackPoint.transform.position, width, height, enemies);
but it gave the error that "cannot convert from float to unity engine vector2
make a Vector2
it wanbts a Vector2
e.g. new Vector2(width, height)
so I assume the reason that you set things like attackTime public is so that you can change them in the editor easily, right? super convenient. But public is actually problematic because that variable can be modified by other code when you just want that code "encapsulated" so to speak. If, rather than public float attackTime you replace it with [SerializeField] float attackTime that code can't be modified anywhere else by any other scripts (e.g. private) AND you still get to mess with it in the editor like you're used to
or i could just be completely wrong and spreading misinformation so someone else feel free to correct me
thanks that actually makes sense to me
so why wouldnt u use the [serializefield] always
just bc it's not needed?
Best practice is to do that
public fields are bad form
sometimes you do need to modify things from outside though, and that's where public methods and public properties come into play
did you resolve this?
i wasnt exactly sure where to put it but i am testing it rn
even though i made it a box overlap only the radius control seems to work? and like change the size
but its also still a circle which im also confused about
oh wait
the gizmo is still saying sphere i think
there won't be a gizmo for your code
the gizmo, if there is one, will be from some component on the object
maybe a CircleCollider for example
i tried putting a polygon collider on the attack point but i couldnt figure out how to make it not solid
yeah this is what i had put a bit earlier
its honestly poorly explained now that im looking at it
ill try and rephrase with a tldr
Does anyone know a good way to have unity rotation work in WebGL?
yes you could use a trigger collider
(right now when i reach the bounds it just leaves the game screen)
but it honestly is worse to use colliders for this than to use queries like OverlapXXX
(and when I set it I cant fully rotate)
This is an extremely vague question. Can you elaborate on what you mean?
What does rotation have to do with "bounds"?
rotation of what
So my rotation is based on my mouse and when i have the game on itch the mouse leaves the game and I cant rotate anymore
lock your cursor
Should that work on WebGL too?
Good idea. Thanks!
this is the line i have currently worked out
Collider2D[] enemy = Physics2D.OverlapCollider(attackPoint, enemies);
but it returns with the error of no overload for method overlapcollider takes 2 arguements. so i tried having radius there and the position transform as before as well as width/height. I also found on a forum someone using filter and results but that did not help the 2 arguments thing
Why are you guessing
ive already read this page over and over but i just dont understand :(
instead of checking what the parameters actually are
Look at the parameter list
and provide what it actually needs
public static int OverlapCollider(Collider2D collider, ContactFilter2D contactFilter, Collider2D[] results);```
^ They write this so you know what parameters go into it and what it returns
based on this,
public static int Physics2D.OverlapCollider(PolygonCollider2D coll, Physics2D physics2D, Collider2D[] enemies);
still returns with errors for Physics2D.OverlapCollider
is enemies at the end just supposed to be a number?
No, it is a Collider2D array
You create the array and pass it in
so the "Collider2D[]" generates the array?
It is the type for an array
GameObject[] is an array of gameobjects
[] is the syntax for array
You have to create the array
what errors?
No it says the type : Collider2D[]
that's just telling you waht type to use
you have to provide an array there
You might wanna show the code you actually wrote instead of the method signature
Posting code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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, that is not at all what you should do
You are declaring a method for some reason there
Just completely delete line 47
If the docs say the signature is OverlapCollider(Collider2D collider, ContactFilter2D contactFilter, Collider2D[] results);
Then you write Physics2D.OverlapCollider(myCollider, myContactFilter, myArray);
You do not include types. You do not have public static int
You just call the method with the right parameters
okok let me try that i think i get what you mean
im gonna have to try this again in the morning i really am not getting it
thanks for the help though!
i will probably be back ;-;\
https://hatebin.com/fofyezamih guys whats wrong with this code? because it should make a vehicle follow the player but i keep getting error CS1026 ) expected
- Learn to read the errors.
- Share the whole error and it's details correctly
- Explain what you have tried to fix it so far.
imma guess !ide isnt configured
💡 IDE Configuration
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
• Other/None
no ones responded to me all day...
i must be invisible or doing something wrong
I even asked twice
I see this
#💻┃code-beginner message
And no other messages
I deleted all of them at this point, thought my format was wrong
Ah, gotcha.
Well I did not see them, and you have not re-asked it. So nothing anyone can really do 🤷♂️
I was gonna reread the rules and post again
Generally if you are not answered, then no one who happened to see it knew the answer. If it was against the rules, someone would have said something
It is just a community server, so questions get missed sometimes
Gotcha.
I'm having trouble with creating an arc for the bunny (user controlled). All the code and more detailed explanation is posted here: https://forum.unity.com/threads/arc-jump-not-working.1602186/
unity forum
Unity Forum
My character is a bunny, I want the user to have to hold down the s key for a few seconds to charge it, release it and the bunny goes in the direction...
People generally don't want to go to links, so maybe that was why it was skipped over.
But in your link you say:
but the bunny doesnt move horizontally left or right, only horizontally
Is there a mistake there? I am confused
Do you mean only vertically?
Well, I am about to go to bed, someone will hopefully help.
I suggest adding a log after each operation and see if each step is what you expect.
I would need to test the code to actually see what is going on myself. Can't do it in my head
you should add debugs or attach the debugger to see what these values are. You can even visualize the direction with Debug.DrawRay. Though really i bet the issue is with that first line
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
This is probably just giving you the camera position
I did add debugs and the angle was given properly, straight up was 90, far left was 180 and far right was 0. Its not applying horizontal force for some reason, just vertical
Show the debugs you've added, I highly doubt you are getting anything other than a fixed number for this angle if the character is staying still
another thing, this clamping probably isnt desirable because you are clamping all negative angles to 45. Going from -179 to 179 degrees is a very very small difference but your code will clamp it to 45 or 135 respectively. Which is basically the opposite direction
the docs for ScreenToWorldPoint also show how to use it https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html. There is something very important you are missing
how to build the game? i am getting errors, building android game.
and error are What went wrong:
Could not determine the dependencies of task ':unityLibrary:mobilenotifications.androidlib:compileReleaseJavaWithJavac'.
Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-33 Android SDK Platform 33
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
what component do i install and how?
I already told you the angles are good
dont know why my mouse cursor isnt there, but at 180 my mouse is to the left of the chracter, at 0 its to the right, at 90 its directly top
this wasnt even the issue i described
did you even test it, genunely curious...
i meant show the actual code for the debugs. Also use Debug.DrawRay to visualize the direction you're getting.
the angles arent a problem dude
when I'm running and jumping it works perfectly fine, the problem i'm having is the force not applying horizontally
🤷♂️ how much do you expect me to test, when the only thing i see from the code is math. Ive pointed out possible issues, i dont know why its a struggle for you to just show me the updated code.
If you're sure the direction is correct, then this is probably an issue with the rigidbody settings. Like friction that might be stopping it from moving
"literally" yet there is a debug in your screenshots, and no debug in your code.
if you want to be a pain to help, then ill simply step out. Ive pointed out 3 possible issues already yet i dont see you addressing any of it
do you really need to see what that is? Debug.Log("Angle: " + angle); how is that gonna change anything? cant you just infer based on the debug.log syntax?
you pointed out nothing to me
you told me it might be the problem with the mouse position, I told you the angles are correct from where the mouse is and the character position
I also told you it works fine when running, its an issue of force not being applied horizontally
you haven't tested out the code yet even thought I gave you all the code
Believe what you want then, when you feel like reading go back and re-read what i said. I pointed out different issues but you're fixated on one thing and clearly ignoring everything else. I cant be bothered to deal with sass. This is just a public place for help, so goodluck getting help in the future if you're an ass to everyone
If you cant be bothered to actually test the code I've given you I dont want your help. I help people with java stuff and since I'm pretty familar with it, the first thing I do is test the code...
if you tested the code you would've noticed that it has nothing to do with the angle, debug arc Im working on adding that, as far as the rigidbody issues I dont know what you want me to do with, I have not changed any settings for the RB, how would I act on you just telling me its an "rigid body issue"
YIKES
I did test, if you cant be bothered to get off your high horse then really no ones gonna help you 🙂. Infact i only noticed this from testing #💻┃code-beginner message
you clearly didn't test lol
"how much do you expect me to test, when the only thing i see from the code is math"
also if you did test, you would know its not an issue with the angles...
if you actually put Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); in visual studio you would know there is no problem with it
dont tell me you've tested...
alright then, goodluck with your issue. Im out and thats a block cause you clearly cant get past your frustrations to even properly read what i wrote. Literally the 2nd word after "rigidbody settings" suggests a possible cause
again, how am i supposed to act on that?
thats like saying "theres an issue with your code"
@plain mortar If you want to be helped in this channel it is expected you share relevant information about the issue and the tests, including results. We don't do guesswork and we don't "trust" users off of their tests, espec\ially in a beginner channel. Please share everything you have done so we can continue from there.
if you tested you maybe would've saw a specific example and I could've done more research on that
I've shared ALL information I have
there is nothing more that I have
if people can't be expected to actually read that information and waste my time like this i dont want their help
legit insane
Alright, good luck on your issue
Consider asking this in #📱┃mobile where you are more likely to retrieve an answer
<@&502884371011731486>
meh i did block, but I had the chat open and its 1 click to read the messages. 🤷♂️ bye child
!ban save 527211132537012275 Would rather insult people instead of getting help. Shutting the door for insults.
lutaic was banned.
Pretty sure it was because of some fucky implicit conversion stuff at a glance anyways
For all they went on about how they tested and debugged it they converted something to a vector3 and then immediately implicitly to vector2
All I see is a complete failure to debug the only 3 values that actually matter. But, hey, what do I know?
Guess we will never know considering they would rather bash the help they retrieve 🤷♂️
Fr
It is usually something omitted overlooked. If someone wants to do a sanity check and go over the exact testing method, it is with the good reason.
Fr
Also like
Debugging remotely is hard
They’re not going places in real life if that’s how they treat an IT tech
Sometimes you just gotta ask questions because usually the real answer is no
It's the same old, making assumptions and refusing to be shifted off them
im mostly sure it was friction, but there were other issues that i pointed out too
yep, debugging the normalized vector, the force applied and the resulting velocity would have cleared up the problem in 5 seconds
what does Vector2/3 do?
it doesn't 'do' anything. It's how you use them that 'does' things
what are they then?
fundamentally they are structures which contain 2 or 3 float values
Hey guys!
Is there a reason why im getting null refrance eceptions in my build from my AI Locomotion script, but everything is fine inside of the editor?
Maybe because an editor script modifies a state that is no longer modified in builds since these type of scripts are not included
Script Execution Order. Check which scripts your AI Locomotion script relies on to run first
How is the execution order diffrent from in editor?
Does Awake run before Start or something like that?
I meant after
Not that, but the sequences of Awake and Start amongst the scripts can/will change. So Awake and Start in one script should not depend on Awake or Start in another
you are ok to rely on Awake in one script/Start in another but not Awake in one script and Awake in another unless you specifically set the execution order
Aleight thanks!
You can still introduce your own methods and add them to the executionorder and change it to your needs, if you really need
no i don't think so, but i dont really know how i can swap the rotation to the player model from the camera
this is probably a stupid question but how do I create a square in code (unity c#)?
Depends what you mean by a square
a game object with the sprite of a square
Make a prefab and Instantiate it
your null ref exception might have something to do with that. Fix it
the problem is i cant diagnose it. you can see the script is definetly PlayerController and you can see that script and nothing is not filled.
So what is line `161 of FirstPersonController?
ohh didnt see in the error it reference the line
crosshairObject.gameObject.SetActive(false);
so crosshairObject is null
oml thanks that was a silly mistake that was meant to be // for later
the error messages do not lie. Learn to actually read them
ok another problem i double slashed everything to do with my crosshair and sprint bar. basically everything that was the problem that i would use later, but unity isnt reading the double slash and its acting as if it want double slashes. and i definetly did save the script so it wasnt that
If it's commented out and you saved the file, it will be used as a comment. If this is not the case then you either commented out the wrong thing, have related code uncommented or you simply didn't save the file
this has nothing to do with prefab but why does this not work?
I want to spawn my cars faster but I can't somehow. The spawn rate (TimeTillNextSpawn) is already 0f. Also I have this function bool CheckForValidPosition() which makes a good amount of space between cars so they don't spawn on each other. Maybe this is the cause I can't spawn cars more faster as it rejects the position for spawning. Please do help me!!
CarSpawner script: https://pastecode.io/s/s8tkvn16
What is the problem exactly? Cars do not spawn in general or after a certain amount of time passes?
I don't see an Instantiate method in this code, so how are they spawned to begin with? This is quite a bit of code
They do spawn, but I can't make them spawn faster
Check your inspector for timeTillNextSpawn
object pooling
Ahh, I see
Did you verify op.SpawnFromPool is being called in general? Does this method even get reached?
also the thing which is making them not spawn faster is most probably my function which makes a good amount of gap between them
yes
Oh, sorry. I misread, it does spawn
timeTillNextSpawn = 1f;
yield return new WaitForSeconds(timeTillNextSpawn);
🤔
cars do spawn
Well, yes. That what Nitku mentions is the thing that stands out
You spawn the car and then hardcode wait a second
i did it to 0 as well, but it doesnt spawn much faster
like yes it does
but not significantly
You don't want the speed to increase, just spawn faster?
like i have this traffic increase pickup, so I want whenever player picks that, cars shall spawn much faster every time
yes
shall I share a gameplay video as well?
What happens if you move the coroutine content into the update methodfor now?
I'm not sure how WaitForSeconds works but considering it is for seconds I would assume that 1 is the minimum
If you want to it be faster, perhaps use a different yield method
like how
For example, get the current time with Time.time, and then wait until a certain amount of time passed
Using yield null; skips a frame
Alternatively, use an actual Timer
what happens when it skips a frame
It will run the next frame
and how do i use that timer to make the cars spawn faster, like very quickly
I still would try update() first to see, if your code can run faster at all
WaitForSeconds does wait for fractional seconds and waiting for 0 seconds waits one frame. I'm assuming the problem is with CheckForValidPosition, you'll have to do some debugging
as I told, that wont change anything as the thing which is causing my cars to spawn slow is the CHeckForValidPosition()
yes thats what i was saying, what do i do with that
Ah, missed that part, sorry
Increase the minSpawnDistance and see what happens
u mean decrease right?
because when I decrease it, all the cars spawn on top of each other lol
I would use async calls and let each object create itself while starting the next one
sorry, what is that?
Explain what you mean by "doesn't work"?
You'll have to tweak the values like spawn distance and radius and find the combination that works the way you want
the gameobjects aren't squares
What are they
Looks like the sprite doesn't exist
sounds like you never made a sprite called "Square" in a resources folder
so like trial and error?
I really really strongly recommend just using a prefab instead of this
That's how it goes
Thats bad habit actually 😉
[SerializeField] public float minSpawnDistance = 2f;
[SerializeField] public float radius = 1f;
[SerializeField] public float timeTillNextSpawn = 0f;
These are the default values, in which it doesnt even look as if the cars are spawning faster, so like how do i even tweak them to make spawn rate faster? like these are the lowest
how do i use prefab for squares?
This is essentially a game design issue, not a problem with syntax or logic
Dont tweak around until it might work. YOU should know, what your code is doing, not fortune or luck 😄
Squares are not special.
Make a prefab that is how you want it to be
And Instantiate it
i mean yes, but i know whats my code doing. I just dont know how do i make it better to achieve my goal
but the radius is how far apart the cars spawn, if you increase that they'll (theoretically) spawn faster
okay that sounds cool, let me tweak and try
where is this prefabs folder
Lol i just realized that my code isnt changing theses values on the inspector, thats why it might not be changing
I have "all prefabs" under favorites but I don't know where this prefabs folder is
... seriously?
or is this a folder you have to create yourself?
yes
yeah mean like i thought it would be so dumb to do that I didnt even check, sorry my bad
Happens, even after years you keep forgetting it sometimes 😄 no worries
haha thank you. I will now try to tweak it
There are no colliders in the path of the capsule cast
One note- You're using a 3D capsulecast. Make sure your game is not using 2D physics for example.
i fixed it but got another thing
where i am wrong at this code lines
im trying to make a simple jump
what was the website where I can embed videos and share here?
Wdym by "another thing"? You have to share what the problem is with the rest of us if you want help
You can directly share MP4 videos here
he says he is trying to jump but that code is far off from anything relevant
my object just falls
Well yeah this doesn't look like code that would jump at all
It slightly moves the position up for a single frame, that's it
public List<UnityEvent<T>> unityEvents;
is there any way to serialize this prettier in Unity?
You should be jumping via your Rigidbody, if you have one
isnt this how jumping works in games
Turn your inspector off of debug mode
No
it's not in debug mode
i dont have rb
Then you need to simulate velocity etc in your code
Hmm maybe
Custom editor?
public class ObjectEventActionSubscriber<T> : SerializedMonoBehaviour
{
public List<UnityEvent<T>> unityEvents;
public EventActionObject eventAction;
private void Awake()
{
eventAction.OnEventObj += InvokeAllEvents;
}
private void OnDestroy()
{
eventAction.OnEventObj -= InvokeAllEvents;
}
public void InvokeAllEvents(UnityEngine.Object value)
{
foreach (UnityEvent<T> unityEvent in unityEvents)
{
var converted = (T)Convert.ChangeType(value, typeof(T));
unityEvent.Invoke(converted);
; }
}
}
that's the whole class
maybe I could add where T : Object
would that help
why not go with object already then?
Ah, got it
public EventActionRaiserObject<MapSector> raiser;
can i write property drawer somehow
for the List of unity events<t>
I try to change the values of spawnRate, but then the whole game lags and the existing cars just disappear after spawning which is kinda weird. Please help me this is happening when I decrease the minSpawnDistance or the radius.
CarSpawner Script: https://pastecode.io/s/f1u7up3j
Object Pooler: https://pastecode.io/s/66wq79uu
Looks like its pooling current ones to new positions?
why would it?
You only have a x amount of pooled objects, right? when do you label them "free" to be used by your pooling system?
yes
100 amount
so if i increase spawn rate
it has to reuse
oh man
what do i do now? Increase amount of pooled objects?
Remember when you said, you know what your code is doing? 😉 You yourself gotta keep track of what is active and what can be reused and so on. Either calculate a fixed number you can guarantee to not reach and use that as minimum objects or let it dnymically decide and wait for the next free object. really depends on your game design and how you determine the amount of cars being spawned, probably with a difficulty increase or what not
at a time 14k cars are spawning lol
what in the world are u doing where 100 is not enough?
i mean i set it to 10
So still some code issues you gotta check against to avoid this spawning endlessly
i fixed the lag and sudden disappearing of cars by setting the fixed amount from 10 to 100. Now I gotta tweak with the spawn rate so cars just dont appear on top of each other if i increase spawn rate
You could check for an amount of time if a new car is available, if not, fallback of creating one to keep your spawnrate constant. But there are many ways to achieve your game design
yeah, understood, THanks!
also, my game lags like hell when The cars are increased, what to do to optimize it? (I already have object pooling)
are you back to 100 cars or still 15k?
3k cars spawning
i mean not spawning
but its using cars from 100 amount. I have 3 different car prefabs, i have set 100 to all 3 of them
that would be 300, not 3k
yeah im sorry, thats 300 cars, but why is it lagging?
You are doing everyting on the mainthread right now. So could be your calculation, some checks on your positions. I would check the profiler what script takes the most time
i have used profiler but How do i check what thing is causing the lag?
u click on a spike..
scroll down, in the hierarchy
and see what methods are taking the longest
Maybe show where you're calling jump as well
can u explain?
You click on cpu usage and down in details, set hierarchy and go through with the most ms time of your scripts appearing for example
oh, okay i will do that now
ah
Editor loop is stuf Unity is doing for the Editor
PlayerLoop is whats going on in teh game (your code)
got it
all of the time is being spent in EditorLoop in this screenshot
facts.. thats twentacles screenshot
you pointed to PlayerLoop, but that's only spending 1.64ms
It was just my project for explanation of the profiler 🙂
oh!
he's pooling soo its bound to be a little heavier on his
🤦♀️
I misunderstood and thought you were helping twentacle
"well, duh, that's twentacle's screenshot..."
twentacle doesnt need help 😄
except with excessive garbage collection times, maybe 😛
i do wonder what my player loops looks like
you should add profiler markers!
they let you measure how much time is spent in specific regions
Blame it on polyspatialcore 😄
(without slamming the Deep Profile button)
900 bytes of garbage?!?
is that alot?
no
but you should make it zero anyway 😁
Its not in your hands sometimes 😄
my AI code currently generates hundreds of KB of garbage per planning cycle (every 0.25 seconds by default). i need to start memoizing some of these objects..
how do u deal with the garbage?
lots of objects that get re-created every time they're used and that don't actually store any mutable data
do u manually flush it?
yea, i get that.. but im askin for your setup..
For example, I have an "Activity" class that represents an action you can perform
wheres the player loop?
for each possible action (say, the player opening the door), I can just create one Activity and re-use it
change the dropdown to Hiearchy
you're focused on the Rendering row
oh yeah, and that's a fair place to create garbage
I don't think you can avoid it with IMGUI
and I don't try to optimize allocations for debug code anyway
My planning system uses pooling to minimize allocations, but the code that dumps the plans out to a file is allocation city
since that's not actually part of normal gamepaly
do u have custom pooling or do u use unity's system?
I'm using Unity's Pool classes
ohh bad-ass
Although this is just going to be a dictionary
you'd call that "memoization"
basically, before you compute f(a,b,c), you see if you've already computed f(a,b,c)
if you have, you return the value it produced last time
It's a bit scary to do it with reference types, since you have to make sure you aren't creating a weird conflict
like, if I stored mutable data in Activity, I'd have to make sure that I didn't have two references to it that don't expect to be sharing the same object
i got a question:
say, I want to spawn an object in a radius.. but i don't want to spawn in x distance from another spawned object..
i can say, if the number isn't valid reproduce another value... and that could happen indefinitely if im unlucky like that..
now i could say, if u dont find a valid number by z amount of loops then give up..
that's called "rejection sampling"
but.. giving up kinda lame.. is this the only way to deal with taht?
note that for this situation, you can use Poisson disc sampling
yea ive heard of this..
it's designed to produce roughly uniform looking points where no two points are closed than a certain distance
there is another option. fill an array with possible valid options and select from that array
i mean, yea that could work..
You could fill a space with Poisson disc sampling and then randomly choose points
but the array would end up being huge.. if i really wanted a random feel to it
(the sampling gradually fills in the space from a starting point, rather than placing down points in random positions)
u saying if u spawn something on Index[p] then don't use p anymore?
If you have a huge space, then you can just do rejection sampling
np, as long as you can build it once and reuse it, memory is cheap
It's very unlikely you'll actually have a problem if the density is low enough
randomized algorithms are remarkably predictable (:
well some of my play areas are pretty small
and im still trying to achieve a random feel
but not much space to work w/ and unity random sucks
you can also pick random points and then relax them
whats relax them mean?
unity's random number generator is fine; it generates random numbers
If points are too close, you push them apart.
ohhh ive never heard of that one
i checked in playerloop, now?
and unity random sucks*
*in my situation, working in small area's i get repeats often
nothing against it.. i'm not gonna write my own RNG for sure
any random number generator that didn't cause overlaps would be a bad RNG
The clustering illusion is the tendency to erroneously consider the inevitable "streaks" or "clusters" arising in small samples from random distributions to be non-random. The illusion is caused by a human tendency to underpredict the amount of variability likely to appear in a small sample of random or pseudorandom data.
Thomas Gilovich, an ea...
i'll look
These dots have uniformly random positions
are you getting a single laggy frame?
if so, you need to select it in the graph view
this looks fine: the playerloop is taking under 2ms
not right now
human brain doing what it does best, pattern matching
yeah
Poisson disk (not disc, oops) sampling produces distributions like this
OHH
i know exactly what that is now
You might also see it called "blue noise"
See if you can catch the game being laggy
you can hit ctrl-shift-p to pause
i keep forgetting the "step one frame" shortcut
isnt it >?
not in Unity, at least
this is exactly what i need to learn
I use something I copied from a blog post. The finest source.
hey everyone! currenlty trying my best to code a simple fishing game :) just wanted to know if anyone knows how to make the rotated fish dissapear once he hits the max he can go (the bottom of the boat)
and the score must go to 1, which i think its fairly easy to code...
Easiest way is to determine the y value of the bottom of the screen and check if the fish doesn't exceed that
Do something like if transform.position.y > 100 I think
since its 2d u can easily check if its position.y is > than ur boats bottom
You can compare the position of the fish to the position of the boat
so this, but with the boat's position on the right side
3-piece
can you explain a lil better? sorry if its asking too much
im really new at this
track ur fish's y property of its transform... fish.transform.y
Do you know how to check the fish position using logging?
Try finding out what its y value is when it's low enough
just drag an empty gameobject to the bottom of ur boat.. and check the y position
that y position will be useful to test if ur fish is above it
soo if its y position is > than the y position u desire
the empty gameobject will make him disappear?
noo.. lol i meant to use it to find out what the bottom y position of ur boat is
No. An empty game object is a game object with nothing attached to it.
and then delete it cuz its just a tool
They can be useful for creating a "reference point"
if (fish.transform.y > catchPoint.transform.y) {
// catch the fish
}
instead of having to do something like this
if (fish.transform.y > boat.transform.y - 0.5f) {
}
where you figure out that value through trial and error
Not really
You should probably just specify a base y value and store that in a serialized value, then you can just modify it in the inspector
Both work
i was meaning this.. like if i wanted to find out what the bottom of my potion was..
i can use an empty gameobject to position right below it.. and know what the Y is.
yes, a field would be smarter :p
you'd still have to trial-and-error it if you don't directly measure the distance, though
But we currently have three answers concurrently happening here, I suppose we should stick to one since it's already confusing enough
okay I already know the position of the y axis... how can i make the fish dissapear when he colides with the boat? thats what im having problems atttt
bc he already has a limit
Your messages suggested the object was merely to check the y value through the inspector, so it can be added to the code and then removed. I agree the object is best to use as reference though
Easiest way is to call Destroy on it.
The gameobject will be removed altogether
ooooo okay going to look into it!
and when he collides with the limit, he will be gone and the counter will be up one, so, its gonna be a if variable right
public class IsAboveY : MonoBehaviour
{
public float YLimit;
void Update()
{
if(transform.position.y > YLimit)
{
Destroy(gameObject);
}
}
}```
does newtonsoft serializer serialize dictionaries?
Yes.
Thank you
It serialized basically anything. Only crappy JsonUtility has trouble with everything
will update you soon
!!
tyy
oh I have trouble serializing vectors. Is it on my end?
Like I read that I have to break it down to pieces
Newtonsoft has trouble with them because the implementation of Unity types are very poorly done
It basically serializes irrelevant data
it still is the preferred way to use newtonsoft's right?
Yes, you can work around it
All right thanks a lot.
I think this repo has good information about it https://github.com/applejag/Newtonsoft.Json-for-Unity.Converters
One catch: JSON object names are strings.
They can't be arbitrary json values
If Unity added a simple ignore attribute to some of its properties then these things would not have been needed, but alas
So if you have a Dictionary<SomeClass, AnotherClass>, then SomeClass gets turned into a string
you can't have something wild like
{
[1, 2, 3]: "wow!"
}
in my case, my dictionary keys could be looked up via a GUID, so I made Json.NET write out the key's GUID when serializing
i think i wound up not serializing dictionaries at all, though, and just writing out lists of keys and values
Where can I learn more about guids?
a GUID is just a 128-bit identifier, a lot like an int (32 bits) or a long (64 bits)
the stuff im watching is using ints instead of guids I believe
I'm using GUIDs because these are all assets, so I just copy unity's asset GUID over!
Ah so all assets have their own guids all right
wohh thanks!
this is the pattern i'm using
along with a JsonConverter https://gdl.space/wesojoyedi.cpp
IdentifiableRegistry gives you an object when you give it a GUID. You'd have to implement that yourself (e.g. by loading a bunch of assets from a Resources folder during startup)
Nice I'll study the links you sent! Thanks again.
hey fen,
my boolean settings are serialized like this
i should at least use base64...
6 bits per character instead of 4!
fancy
neat (:
is it trying to spawn once per frame? i see that it slows down as it goes on
(or maybe a fixed number of times per frame)
oof, idk i found the best repo i could find
there a few assets on the store but their paid
if i animate an model with only the basic like Head, torso, stomache, etc and put on an animation that moves the jaw, and finger. Will it still work?
if all of these are Humanoid animations, then Unity will just ignore the parts of the animation that your model's avatar doesn't support
Okay
wdym. how did you even put this together then?
rotate the player objct, you have a reference to player don't you?
yea im pretty sure i have a reference to player, the rotation seemed to work fine just a few days ago and the player was rotating too, i don’t really know what broke it though
the rotation is "stuttering", how can i fix that
private void HandleMouse()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
transform.Rotate(Vector3.up * mouseX);
turn -= mouseY;
turn = Mathf.Clamp(turn, -85, 85);
cameraHolder.eulerAngles = new Vector3(turn, cameraHolder.eulerAngles.y, cameraHolder.eulerAngles.z);
}
private void Update()
{
HandleMouse();
}
* Time.deltaTime you should not multiply Mouse inputs by deltaTime. Ever. it already is timeframe independent
without it, it's still stuttering
regardless you should not have it
did you actually make the change and test it again?
i've tested it before
fix it and make sure you're still having the issue
i do
if it persists: is it always stuttering, or is it only doing that while you're also moving around?
always
Is there a rigidbody on your player object?
yea
you should not be directly modifying the transform, then
especially if Interpolate is enabled on the rigidbody
the rigidbody will overwrite the position and rotation every frame
Shouldn't be. Remove it, save it, test again, and make sure you reduce sensitivity
You're rotating in Update while rigidbody processes movement in FixeUpdate
ah yeah that's your problem too
rotate the Rigidbody instead
rb.rotation *= Quaternion.Euler(0, mouseX, 0);
note that this means that the camera will only yaw 50 times per second
if you have Interpolate enabled, this will get smoothed out, but it'll also get a tiny bit of delay
nah this one can be done in Update
Setting the position or rotation of a rigidbody does nothing until the next physics update.
Changing the rotation of a Rigidbody using Rigidbody.rotation updates the Transform after the next physics simulation step.
well, sure, it works
