#💻┃code-beginner
1 messages · Page 777 of 1
and don´t forget the post processing effects
!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.
testing smn
private void InputManager_OnLeftClick(object sender, EventArgs e)
{
//check if we hit anything
if(MatchManager.instance.currentPhase == MatchManager.PhaseType.preparationPhase)
{
if (GetObjectHovered(out GameObject objectClicked, MatchManager.instance.ClickableObjectsMask))
{
CheckObjectType(objectClicked);
}
}
else if(MatchManager.instance.currentPhase == MatchManager.PhaseType.actPhase)
{
if (GetObjectHovered(out GameObject objectClicked, MatchManager.instance.DominoSpacesMask))
{
CheckObjectType(objectClicked);
}
}
}
okayyy icic yes
wanted to know how to make it colourful bc I've seen others do that
ignore me :3
keep in mind that remainder and modulo are not the same operation
% in quite a few languages, including c#, is actually remainder, not modulo
that Repeat is an actual modulo
Are they not? I must be misremembering then i havent used it in awhile
Yeah no looked it up some found that python ( where i first learnd of it) calls it modulo but most call it the remainder operator
they are similar but not equivalent.
-5 / 3 = -1 R -2 (euclidean division, remainder -2)
-5 = 1 mod 3 (modular arithmetic, residue 1)
do you use the same oncollisionenter2D for different types of collisions? so like, on collision, you check whether the object it collided with has a certain tag or not and then do the needful?
yep
what alternative would you have in mind lol. unity only sends that message
Hey, when using an audio source and making a webgl build I get Failed to set the 'loopStart' property on 'AudioBufferSourceNode': The provided double value is non-finite. with Unity 6000.4.0a2, would anyone know how to fix that?
how can i get mouse pos in format from -1 to 1?
i guess you would use screen.width and screen.height and basically remap them to the "-1 1" range
how can I get a local directional vector spun in worldspace so it's direction is relative to another directional vector? Like movement direction relative to camera angle?
transform.forward can be used
like _camera.transform.forward * Time.deltaTime * _speed
I can't figure out how to make use of transform.forward. What you described would only be a single axis aligned with the camera, I want to use a flat 2D vector to describe top-down movement
do you mean on one Axis ?
alr solved
wait a sec\
transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * _speed + transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * _speed
make sure that transform points to player's body
so you cant nullify your forward vec by looking up or down
you could factorize that quite a bit
factorize?
he said aligned with the camera tho, would you not have to consider that
i think he just did not explain it correctly, what you provided should be working
it does work
i already use that in my script
i made ingame freecam mode
i know it works, i wanted to say works for him
ok
Thank you~ I made it work with this for now, didn't realize about just adding two vectors together like that
Vector2 vel = new Vector2(cam.transform.forward.x, cam.transform.forward.z).normalized * inputDir.y + new Vector2(cam.transform.right.x, cam.transform.right.z).normalized * inputDir.x;
If the GC is doing a sweep is it automatically slower if there are more objects created? IE I have 1k cached objects and the GC sweeps to destroy a few that are not cached is that sweep automatically slower versus if there was only 100 objects cached?
I used Brackeys tutorial for fps movement so i can get well... movement, however i want to be able to drag items with the mouse and kinda throw them around (that i gotta figure out later lol)
the issue right now is whenever the (locked) mouse goes over the item (in this case a cube) the camera moves much faster than before, im using the legacy input system along with OnMouseEnter and Drag
do i need to use the new input method? Or should i be raycasting from the camera? Right now i simply want to fix the camera movement so any help with that would be greatly appreciated!
if needed i can share my scripts, its nothing special anyway
also, when playing "maximized" the issue appears to go away, so it might just be the unity window size messing things up, although i still don't like how this issue exists and a fix to prevent possible issues in the future would be nice
New input should not matter. You'd probably end up doing similar logic anyway with it
Anyway, if you've issues with some code feel free to post
absolutely no idea why this is happening. the error pops up by itself. but then when i restart the paused game, it work fine
the gameObject has a spline animate attached to it, so when it's supposed to end its journey, it's splineanimate is supposed to become false, so when i reenable the object in the pool, although it becomes active, since its spline animate become false, it doesn't move across the spline. that's why i am restarting it...
you need to look at enemyAni.cs line 38
you have a NullReferenceException happening there
also for future reference, a screenshot of the error would have been sufficient rather than a video where 90% of it is just you wiggling your mouse around uselessly
i thought that the delay in the error might mean something...
have no idea why it doesn't happen right after i hit play
it's not happening until it happens 😛
is it because of this?
📃 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.
share your code properly
you should consider rubber duck debugging sometime
@slender nymph it might have been you who sent me smth related to a doc which explains how to debug code and stuff...was it you? or if you do have one, i need it...
not entirely sure what you're referring to, but i've probably sent you countless links to unity.huh.how which has debugging steps for many common issues
what problem?
why did you share the same image again lol
For the shadow thing that is not code related. #1390346776804069396
so we dont have Q&A general channel ?
learning how to make 3d game make me depression
what's that? i don't rly know how to use the debugging software which comes with visual studio...
we have several channels for specific topics, and #💻┃unity-talk for issues that don't fall into any of those specific topics
if your issue is about the shadow, the specific topic would be #1390346776804069396
ok
my b
does .db file saved on Application.persistentDataPath get shipped too when i build my game?
no
Put it in the assets, when the app starts if there is no db file in the persistentDataPath, save a copy of the asset there
the docs tell you exactly where these files end up
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Application-dataPath.html
and yea just save it to the assets folder. It's the same if you wanted to include any file
but then will the directory be the same when it is on other device? let's say android. how to specify where the db file is
it doesn't tell where the file will end up. when i put it on asset folder
??? the path is Application.persistentDataPath
🤔 what are you actually trying to do here
no, i need the .db file to be shipped too
so i can't use that
jesus christ
because if you include it in the assets file, you just directly reference it. theres no need to "find" it. the same way you would do with a prefab
i just want my .db to be shipped too
Put the .db file in the assets
thats not what you're trying to do. what, in game design terms, are you trying to do?
then copy it to persistentDataPath
oh... okay thx 
StreamingAssets may be better suited
Based on previous questions, they're trying to include SQLite in the game and can't figure out where to put its database files
or use the file as a TextAsset as you can then read the bytes of the asset and use as desired
wait no, i should not have 2 copy of db
i will try this. thx.
there is nothing niche about this yeah?
The database file needs to be writable so this won't work
I realised this after posting 🤷♂️
Example usages include:
Configuration files in JSON, XML, SQLite, or other formats.
Oh yeah this perfect
i see, thats mostly why I was asking about the actual feature they want to implement
If this DB is for player save data then do not use streaming assets
Except that you won't be able to write to it
Use streaming assets to store a default copy that you can copy into persistent data path
well realistically you cant ship data then and keep it writable without having 2 copies. Consider the shipped data just a template
if the data doesn't exist in persistent data path, use the template
i see... i guess i will need 2 db then
What is this DB for even?
Having the template doesn't mean you have 2 databases
database
what is it for
game data?
I'm putting all things in there. my game goal is still vague
Then why are you using sqlite 😐
yes
how else do i save offline game data?
You can surely then just use persistant data path and make a new file if its not present?
Beginners often use json, otherwise id recommend binary formats.
Sqlite is good for situations where you actually need the benefits of db querying
Seeing as this is code beginner i am confused
yeah... so like 2 db. one on the build and one for presistant
there are tons of resources out there which answer this question exactly
you're kinda just guessing at how things work here
No, can you clarify why you think there should be two?
i am... I'm learning
The cart is being put firmly before the horse
If you cannot produce a new file state correctly from code only then that isnt a good sign
learn how to fly a plane before you can walk
honestly I am more concerned why you think its acceptable to post this screenshot in a safe for work discord channel
like take your weird hentai somewhere else no one wants to see softcore porn in a programming server
because i can't edit any file on the asset file yeah? so i need to copy it, and put it on persistance data path. so there is 2. one is the og that i can't edit, and other one on persistance pathi can edit
Anyway ok thx everyone
when we ask questions like what you're trying to do, it's better that you state the feature you're trying to build like "save the amount of coins of my player has" rather than "ship a DB file". this is called an xy problem https://xyproblem.info/
it really just doesn't sound like you need a DB at all
The usual way to do it is to start with an empty database, so you don't need a pre-made database file
You miss understand. If you have gameplay configuration this should be SEPERATE from player save data.
These should not be mixed together.
If you need stuff in the database when the game starts then the game puts it there dynamically
or you could just make a post build editor script that copies it to whatever directory you want.
beginner channel btw
ignoring the fact that its not even needed for this problem, low lines of code doesn't mean a beginner will understand it lol
no one said anything about File.Copy
Idk i just see people telling him he doesn't need a DB and there isn't enough info about to determine that.
isn't that the point of followup questions
that's why https://xyproblem.info exists as a resource
i found better solution someone send me this link
https://www.mongodb.com/developer/code-examples/csharp/saving-data-in-unity3d-using-sqlite/
and tell me to use URI (URI=file:SqliteTest.db) instead
they say that way i can ship and edit the db
I doubt it works but try it out (in a build) and if it works for you then great
Hello, I'm a begginer in Unity and C# and i got a problem putting a velocity to a Rigid Body
It only says this in the console: NullReferenceException: Object reference not set to an instance of an object
this means you're trying to use an object but it is null. show the relevant code with the error
you likely just never assigned the RB
The object has a rigidbody
It starts inactive but it gets activated at some point but without any speed
!code for sharing code in the future
📃 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.
you dont assign the Rb a value anywhere in this code, and it is not serialized to inspector so it is null
id really recommend starting out with c# basics (resources pinned in channel) if you don't know what null means
In another object I put the same line and it worked, this one just doesnt
ignore the other object, it's not relevant to your problem here. focus on what i said above #💻┃code-beginner message
You need to either get the reference through GetComponent or serialize it with [SerializeField] and assign it in inspector
it is null, give it a value
because you cannot have a member with the same name as its enclosing type. change the name of your variable. or change the name of the class.
Iirc PlayerActions is a name used in the auto generated class. You just need to change the name of the asset I believe
oh why does it default to same name if it gives an error then weird
in what way is it "defaulting" to the same name? you typed the name
no i just pressed generate c# class
The name used is the asset name
or the name typed into the convenient box to enter a name
huh
so it cant be called player actions
why cant i cast (float[])? I made a list of 5 floats but it errors despite all floats being dorrectly written
{
foreach (var x in [-0.5f, -0.25f, 0, 0.25f, 0.5f])
{
if (Physics.Raycast(transform.position + Vector3.right * x, -Vector3.up, 0.5f))
{
return true;
}
}
return false;
}```
you can't declare arrays like that in the version of c# that unity uses
how do I make an array then??
oh
the normal way . . .
the normal way that is the only one I have ever seen is [], cause I have always thought of {} as either a set or a code block
even the official c# docs call out how to initialize an array correctly when using a version of c# before 12 (when collection expressions were introduced)
your code looks evil. not even talking about the loop header
well what do you know, {} is erroring
{
foreach (var x in {-0.5f, -0.25f, 0.0f, 0.25f, 0.5f})
{
if (Physics.Raycast(transform.position + Vector3.right * x, -Vector3.up, 0.5f))
{
return true;
}
}
return false;
}```
well yes, you can't just do it in place like that either. you need a variable to assign that to
you should have searched how to do it using c#, then you'd see how it's correctly done . . .
and Im doing it exact as its shownn
no you aren't
x is ther variable
??? I searched C# arrays and it showed {}
wrong variable mate
x is the only variable i use here
you're skipping/missing steps. you just replaced the brackets with braces. look at and read the page they sent you . . .
yes, but what else did it show? give me any example you saw that declared an array in place like that and didn't assign it to a variable
it shows braces insyead of brakets
I didnt know that arrays couldnt be on their own
that's the whole point. you need to store your array in a variable
you need to assign the array to a variable. x in this context represents each element (item) in the array . . .
I didnt know that
#💻┃code-beginner message
and literally every example ever
because you didn't take the time to read. the page tells you about storing multiples values in a single variable, how to declare an array, and define the variable . . .
its saying that the variable I made last line doesnt exist????
const numbers = {-0.5f, -0.25f, 0.0f, 0.25f, 0.5f};
next line has numbers but nope
even with collection expressions, you still can't just declare an array in place. the only way you would have ever seen any example doing that is if you were looking at examples from a different language
and where is the variable's type?
last time I tried doing list of floats it didnt work
not Array<float>, not float[], nothingggggg
also you can't make an array constant (at least not one you declare as a local variable)
whyyyyy
because you were declaring it incorrectly (without storing it in a variable). you need to do each part of the variable declaration correctly . . .
take a few minutes and look at this: https://learn.microsoft.com/de-de/dotnet/csharp/language-reference/builtin-types/arrays
at this point it seems like you need to review the basics of c#. there are beginner courses pinned in this channel, start there.
what reasons are there as to why any of this needs to happen?? why cant arrays be constant? why must they be in a variable? why does declaring an array of floats use float[] but arrays use {} (and {} is the same as code blocks)
arrays are reference types so cannot be constant
arrays can be constant, just not like that
dont think they can work like c/cpp arrays
how??
declare it as a field
ah wait, they can't be constant but it can be readonly that's my bad.
IReadOnlyCollection and IReadOnlyList are the best way i know to have a non writeable collection
isnt that the same thing? constant -> cant be modified, only read; readonly -> cant be modified, only read
curly braces have more than one meaning; it's not just scope. it's used for initialization as well. c# declares an array using [] square brackets, that's just how the language works. you need to assign an array a variable because it's a reference type. without a reference, once you declare it, you can't access it again, but the reference is lost . . .
readonly fields cant be re assigned, its not the same
C# doesnt declare an array with [] it uses {}
so you can change the value of a constant?
no, constant means it is literally a compile time constant. readonly just means the variable cannot be assigned to after initialization (any properties on that object could still potentially be modified though)
constants arent variables technically
no, readonly fields can be initialized inside of a constructor, so its value can changed/assigned once . . .
and a constant cant be changed after being made either
so you can change a constant?
whats the point of it being constant
they are referring to the type, to declare a variable of an array type you use [] on the type to signify it is an array.
also c# does use [] for array initialization, as of c# 12 which unity does not yet have access to
constants are a way to define some rvalue that can be used in various places
so how is it possible to change the value?? if its constantttt
a static field would be a shared var you can read/write to
but... it doesnt change its static
okay you clearly have lots to learn
static just means its not a class instance variable
ok but what is the difference between can only be set once and can only be set once
no, you cannot change a constant because it is not a variable to change, it is resolved at compile time and whatever the value you declared as constant is put in place of where you used the variable at edit time.
take this example
if you look at the results you'll see the constant "x" has been replaced with the value given to its initializer
const int DEFAULT_BOXES = 5;
public static int Boxes = DEFAULT_BOXES;
Boxes can be written to and read from. DEFAULT_BOXES is not a variable but just a re usable int we can use at compile time.
its like doing #define DEFAULT_BOXES 5
boxes is static though
static can be changed, it just means it isn't owned by any instance of the object. const cannot be changed.
static means not changing
are you trolling us or what
static means something that doesnt change
say potato if you are not a bot
in c# it means something else
"lacking in movement, action, or change, especially in an undesirable or uninteresting way"
in other contexts, sure. but not in c#
potato
STATIC DOES NOT MEAN THIS IN PROGRAMMING PLZ
okkk
If we explain something then trust us
ok
in the current version [] brackets are used to declare an array with a variable type. {} is the initializer. they are two separate process. combined is the initialization process . . .
im still confused about how a readonly is different from a value that cant be changed
A read-only variable is still a variable.
A constant literally swaps the value with the hard-coded constant at compile time. The constant you define does not exist in the compiled program
const must be a compile time constant. you cannot create an object for a constant, but readonly means it can be assigned to either in a field initializer or the object's constructor so it can have things that are not constant assigned, but after that it cannot be assigned to again
but they behave the same
they do not
As such, it can only hold compile time values. A read-only variable can hold a reference, but a const must be a constant value
how are they different? can the readyonly be changed
i literally just explained
so is that why an array cant be a constnat
If you're gonna ask a question you should read the answers
Yes. Arrays are not compile time constants
oh
yes . . .
im facing a issue with Road architect where the wizard doesnt show anything innit when i try to use it, i tried re installing didnt workout
#💻┃unity-talk is more appropriate for asset bugs but i dont think we can help you in general unless its a very common bug on a very common asset.
Touching on a point from earlier, are you sure you haven't seen some code like this?
var foo = new float[] { 0f, 1f, 2f };``` @stark vessel you said that arrays only use {} which isn't true
float[] foo = { 0f, 1f, 2f };``` would also work, but you still need []
Hello everyone!
i'm having a problem with build to a apk
I anyone help me to fix this i appreciate
did you check if target was null?
also, don't use Find in OnTriggerStay; it's called every FixedUpdate. Find should not be called every frame as it checks every GameObject in your hierarchy . . .
why is it still returning a null ref error 💀
EnemyCollision.OnTriggerStay2D (UnityEngine.Collider2D collision) (at Assets/Scripts/Collision/EnemyCollision/EnemyCollision.cs:17)```
so...only on enter got it
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
public class ShootBullet : MonoBehaviour
{
GameObject Target;
[SerializeField] GameObject bullet;
void Update()
{
if (Target)
{
Vector3 direction = (Target.transform.position - bullet.transform.position).normalized;
int movespd = 30;
bullet.transform.position += direction * movespd * Time.deltaTime;
if (Vector3.Distance(gameObject.transform.position, Target.transform.position) <= 1f)
{
Destroy(bullet);
Destroy(Target);
}
}
}
public void Create(Transform start_transform, GameObject target)
{
Target = target;
Instantiate(bullet, start_transform.position, start_transform.rotation);
}
}
Because bullet is null
did you check bullet as well?
ahh wait a sec
you should get the shootFromPosition in Awake or Start. you only need to grab it once . . .
sry i did not check
When you get a null reference, look at the line and check any variables before a .
one of them is null
you check every reference variable on the error line . . .
oh ya bullet is null
why isn't movespd an inspector variable so that you can tweak it to ensure the proper speed?
i will get to that once it happens...
make it a habit
to not hard code stuff like that.
no point youre just giving yourself more work later on
also, bullet doesn't need to be a GameObject. if you're only accessing its transform, then use a Transform type instead. this avoids an extra get call from bullet.transform.position to bullet.position (thought i'd change the variable name to bulletTransform or smth . . .
the same way you're accessing gameObject.transform.position; it can just be transform.position . . .
well you see, i am instantiating a bullet, so i am afraid it is gonna be a GameObject but i will use transform for the other things you mentioned
wait, does transform.position work instead of gameObject.transform.position
i just said that . . .
i misunderstood you
actually nah, i was focusing on the big green text instead
i am stubid
when you instantiate, a GameObject is created, but you don't need to store a GameObject variable. it's easier to store the type (component) attached to the gameObject that you actually need . . .
it's pointless (not entirely) to ever need a GameObject variable . . .
every Component has access to its game object, so there's no reason to store a variable for it . . .
another question, i have no idea as to why it's happening. the Bullet gameobject has the Bullet prefab attached to it. on instantiating this gameobject though, the prefab disappears...any reason as to why it's happening?
wait, so like if i took a Rigidbody2D hoo and then i said hoo.gameObject.transform.position that would work out?
yes, exactly . . .
i did not know that
but you don't actually need the .gameObject. it can just be hoo.transform.position . . .
because Rigidbody2D inherits the gameObject and the transform property from Component . . .
this seems weird. the Bullet prefab has a component with a variable assigned to itself (its own prefab)?
ya, i prolly made a blunder or smth
so like, the droplet is a unit which the player deploys, and it has a collision script attached to it, which detects collisions with enemies. what i want to do, is to make a bullet gameobject in the hierarchy, and then attach a script to it, which has a Create function in it which instantiates the bullet. and then, i wanna update the position of said gameobject in the update() block of the code. thing is, if i do that, and then i destroy the gameobject, i will end up losing the gameobject....and well, after typing all this down i realise that i am trying to destroy the prefab itself when i call the destroy function
ideally, i want droplet to have a script, which spawns a bullet and makes it go towards the desired target. i know how i will update the position, i don't know how to reference stuff, and been trying to think
has anyone figured out how to get unity errors in the cursor?
How do I get OnTriggerEnter to work with unscaled time instead of scaled time?
I'm having a weird issue with a script where, depending what object in the Hierarchy I have selected, will change how the script seems to behave
It's a generic player controller for a character, and when I have the Player object selected, it behaves as normal. View-sensitivity is normal and I can look around with the expected sensitivity, and my jump height/gravity is as it should be
But if I select any other object in the hierarchy (be it the world, the camera itself, or even nothing in the hierarchy), suddenly the view-sensitivity goes way down and my jump height gets completely slashed.
Any ideas?
Probably due to reduced performance, meaning your code may not be frame rate independent
I'd be... Surprised if that's it, the project is exceptionally barebones right now (it's essentially just a big cube to walk on and a capsule character) so I'd be startled if the act of not looking at a object in the Hierarchy is making such a major impact
Regardless, if it is that, what would be the method to fix it?
I figured the whole "multiply stuff by Time.deltaTime" would be the general method, but perhaps I'm looking at it backwards and shouldn't multiply it by that?
As an example, this is what I'm doing the view stuff with;
private void CalculateView()
{
newCharacterRotation.y += playerSettings.ViewXSensitivity * (playerSettings.ViewXInverted ? -input_View.x : input_View.x) * Time.deltaTime;
transform.localRotation = Quaternion.Euler(newCharacterRotation);
newCameraRotation.x += playerSettings.ViewYSensitivity * (playerSettings.ViewYInverted ? input_View.y : -input_View.y) * Time.deltaTime;
newCameraRotation.x = Mathf.Clamp(newCameraRotation.x, viewClampYMin, viewClampYMax);
cameraHolder.localRotation = Quaternion.Euler(newCameraRotation);
}```
you get a rubber duck and talk to it, you gotta be a bit crazy and lonely but with enough time programming you will get there
pun intended?
which pun
drawing the inspector can be very expensive. Show how input_View is retrieved. I would be shocked if Rob is wrong. You're probably using an API that already handles framerate independence. It's a frequent mistake
no, rubber duck method existed before your game, the pun was that after you program a lot you will be crazy and lonely, therfore already talking to inanimate objects
but it does help, speaking out logic helps you realize where the error in logic comes from
It would indeed appear to be something like that
From what I see having fiddled a bit, some of the floats used in my script, which I had set as public so I could see them, update so aggressively that having them visible was making quite an impact on FPS (Things like the current gravity value on the player, as an example)
Setting these all to private to stop them showing, now results in the behaviour being the same regardless of object
So while I have indeed fixed this part of the issue, it does concern me for future things as evidently my movement code (looking around/jumping) is very dependant on the FPS of the client, which is clearly not desirable
The part that does leave me confused is the fact that I thought Time.deltaTime was meant to sort of address this? By having things like camera-movement multiplied by said deltaTime to stop it being entirely FPS dependant?
no, you misunderstood the issue and applied an incorrect band-aid
Then I am still lost 
any way to apply force with a rigidbody without the force carrying over to the next frame
you are using an API that is already frame-rate independent, and breaking the frame-rate independence by including delta time again. Where is input_View received? Find the docs for the API you're using (I'm guessing Input.GetAxis) and read them
where can i display something fun i did, sorta like a personal acomplishment while learnin
I'm using the built in Input System, assuming that's what you're referring to?
i meant a video lol
thanks man!
oh
yes, look at whatever is setting input_View value
can i add force to a rigidbody in a way that only affects that frame?
yes, did you check the docs? impulse/velocity change for 3d, otherwise impulse for 2d
velocity change would affect velocity
probably impulse
they're both impulses. One considers mass and the other doesn't. Both will affect velocity, assuming it's valid to apply force to the body
I dont want to affect velocity that would affect next frame, going against my entire message
your message makes no sense, then. You want to apply a force that has no effect?
Adding a non zero force is going to affect velocity 🙂
I'mma be totally honest I'm still lost to what this actually means, I'm basically just starting out with Unity (and code in general for the most part), so I'm not sure what this really entails :c
move it, then set its velocity to 0 on the next frame
Cant do that, theres other things that affect my velocity I want to stay
your code is using the input of a variable called input_View. Identify which line of code in your project assigns input_View to determine how it's getting its value
I wrote a custom network library using enet. I am not a fan of how I designed replication, anyone know some decent articles on this subject? What I mean by replication is the management of network aware objects ie creation, deletion, updates etc
copy the velocity in a variable, then set its velocity to the new velocity, then next frame set it to old velocity
defaultInput.Character.View.performed += e => input_View = e.ReadValue<Vector2>();
It's also set as a private Vector2 near the beginning of the script itself
doing that its working nice but gravity seems to be applying after my update() method causing gravity to be really slow
This is the new input system. Is CalculateView in an Update loop or FixedUpdate? Check your input actions for what's happening with Character.View binding with the mouse. I assume it's using delta position which is NOT frame rate independent by default
maybe you could manually add a small downward force? if it only applies when you are doing this special velocity stuff you can probably edit the old velocity to match what it would have been if it kept going normally
maybe
im full of dumb ideas so my reccomendations probably aren't the best, so if someone else says something id reccomend following them lol
CalculateView() is in an Update, not a FixedUpdate
As for Character.View the only appearance of it in my script is this line;
defaultInput.Character.View.performed += e => input_View = e.ReadValue<Vector2>();
Which appears in a private void Awake()
You can apply a one-time instantaneous velocity change with a force on one frame. What are you trying to do, exactly? Hopefully you're not trying to work around a misunderstanding
I want my walking to be smooth
I dont want turning around to be difficult
or like I want it to only move left or right when you hold the buttons, like hollow knight
you must have set up an input actions asset, you should be looking in there
Ah right
View is set as a Pass Through, Vector 2
And the actual Mouse itself appears to be set as Delta, assuming this is what you're referring to?
did you set this up yourself? Why pass through instead of value? Other than the action type, this looks correct to me and you should be including frame delta time in your code
Following a tutorial I’d found that seemed to be working fine up until I noticed the issue with the selected object changing the way it behaves, which is what sent me here
Though I suspect I may well have to find a new guide
The issue I have is that, being entirely new to it all, I’m mostly following guides and tutorials and going from there, so if the guide leaves something as a pass through for example, I just don’t know enough about anything to question if it should be a pass through or not
If you're setting timeScale to 0 and still need collisions, use Physics.Simulate in Update to advance the physics world . . .
You pretty much said it. Place the script on the object, call a method from the script that creates a bullet. You just have a few minor missteps
When the bullet is created, set its orientation (rotation) so the bullet only needs to move forward. The bullet should move forward in its own script (or the script that created it can set its speed, but this option depends on how the bullet moves)
The bullet component (script) should be on the bullet GameObject, not the droplet, because the droplet is not a bullet
The droplet needs its own component with a method that shoots a bullet. It needs to have the bullet prefab to create the bullet that shoots . . .
Adding any type of force will affect velocity. You'd probably have to set its position (teleport) . . .
was about to ask a question but figured out that AnimatorStateInfo.GetHashCode and AnimatorStateInfo.fullPathHash are different things, god I hate names
hello, i am following this tut but I have deleted the default Player input scheme and created my own that is a recreation of it for practice, same names etc. But when i get to callback context near the end of the tut, Move dosen't show up, is there a fix for this?
https://youtu.be/DQY62meLVCk?si=jqG80y8idiOE1QiW
Beginner friendly and full tutorial on Player Movement using Unity's Input System! We'll also set up a default sprite for our player using the asset pack below. And look into serialized fields!
Sprite sheet: https://pixel-boy.itch.io/ninja-adventure-asset-pack
Full Package: https://www.patreon.com/posts/movement-with-2d-104791237
Free Script: ...
or maybe an alternative way to do it
!code needs to be sent for anyone to help
📃 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.
oh ok sorry
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
private Rigidbody2D rb;
private Vector2 moveInput;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
rb.linearVelocity = moveInput * moveSpeed;
}
public void Move(InputAction.CallbackContext context)
{
moveInput = context.ReadValue<Vector2>();
}
}
ok ive changed back to using the default but it still dosent show up
there should be a CallbackContext: Move
- make sure you have saved your script
- make sure there are no compiler errors in the console
!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.
ive done that and now the move function has showed up, but it dosent look like its working, the character isn't moving
Send a screenshot of the full inspector
Could u scroll down on the inspector and extend the events tabb
Extend the events tab in player input pls
Oh wait u didnt assign the map
Yes?
Assign it
tysm
How do i get a 3d object to be rendered behind my UI, not in front
Canvas is set to Screen Space - Camera, main camera is assigned
my scene has only 1 camera
The 3d object is on layer Water
Cameras culling mask is set to Water, UI
I am using Unity 6. The 3d model's material is URP lit
Make the plane distance of the canvas smaller than the physical distance from the camera to the 3d object
What is the plane distance
The distance of the UI plane from the camera
What is a UI plane, and a canvas cant be moved
maybe u are confused with world space
Look at the inspector for the Canvas
You're looking at the RectTransform
huh
Wait i just changed that my accident
It needs to be in screen space camera
Yes now you can see plane distance
the distance from my camera to my player is ~3,
when plane distance is 2.9 it doesnt show
2.95 and it only renders a bit of the players front
What do you mean by this
Looks like we succeeded at putting the 3d object in front of the UI no?
i wanted it behind
Well you can just use overlay then. Overlay will always be drawn on top
Otherwise, make the plane distance smaller than the distance to the player
Note that if your player here is 3 units away from the camera he still has some thickness
So the closest part of him might be 2 units away, for example
How do i do this. the 3d object doesnt get rendered if i use overlay
For this I need a second camera and add it to stack?
That means you must have some giant UI image blocking everything then
What do you have in your canvas?
By default it will just work, no need for second cameras. Overlay doesn't even use a camera
But if you made a giant image covering the whole screen of course it will cover everything
what the hell
im so stupid
I do have a bg which covers the whole screen though
so i dont know how to work around that
Put the background image on a separate canvas in screen space camera mode with a high plane distance so it's behind everything
Put the overlay UI on an overlay canvas
Worked perfect
thank you
Just wondering where should I hide the big background
is this fine
I don't know where to ask anymore. Who knows how to fix this? Texture in paint texture that im trying to paint appears far and randomly from my brush
anyone know why my character only displays walk down? the idles work but not the walk.
can somebody explain me the difference between sqrmagnitude and magnitude ?
sqrMagnitude is the magnitude squared
sqrmagnitude is the magnitude squared
Jinx
lmao
it's faster to compute because computationally, division and square root are hard operations
(division isn't used here, just thought i'd mention)
magnitude is comouted from the pythagorean formula, consider a Vector2
magnitude^2 = x^2 + y^2
magnitude = sqrt(x^2 + y^2)
yea ik but why do we have both ? if i have sqrt then why to use .magnitude?
Missing a little info here like how your params feed into this blend thing
getting the magnitude involves a square root, a relatively hard operation - the sqrmagnitude is much faster
To get the actual magnitude
because for a lot of things, sqrMagnitude isn't super useful.
oh ok
it's good for comparing magnitudes, and that's about it
The square one is "good enough" for a lot of things and much faster to compute
To get the actual magnitude
!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
what?
configure your ide
it is currently not configured
this is a prerequisite to getting help here
wait, did you configure it (or more likely, it loaded) between these 2 screenshots lol
this one seems to show it's configured?
uh no i didn't do anything
can you show a screenshot of your ide as it is currently
It is configured
Well you didn't show what I asked about above
This
How you fed your animator params into the blend
it just checks your x and y inputs and works out your direction
im not 100% sure, its a tutorial
show your blend tree configuration
I'm asking you to show me how you set it up
alright gng i am facing a problem
!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
I wrote my own binary reader that uses bit converter and block copy to read binary data
you can just ask your question without leading with this
the problem is that I am facing an error OutOfMemory
potentially could be a long running or infinite loop that keeps allocating memory
yeah, that was a vague guess based on the little info you gave
it fails at reading the next file
can it give the same error if the file has just ended?
you need to scroll up in the inspector to show what params it's using
ok
anything's possible. you haven't given any usable info here
we can't read your mind
have you tried debugging to see what codepath is triggering the error?
that wasn't for you
it gives error at the last line LoadAnimation
the previous animation is loaded and works as intended
tysm
has anyone else ran into an issue where 3d objects refuse to render if 2d objects are around? it doesn't matter on positioning, if the 3d object is overlapped, in front of, or behind the 2d object. I'm trying to make a shimmering force field and figured a 3d object might add a little extra pizzazz but I've been banging my head against a wall for the last 4 hours trying to get it to work. the only time it does anything close to working is when I change the surface type to opaque but that defeats the point of having it there
Sorry if this is long, trying to provide info that might be valuable. Tried many troubleshooting steps prior to this
doesn't sound like a code issue
rip, was hoping
...why would that be a code issue
what are you using array for? you aren't using it for anything
anyways, the issue could be in that call
!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.
ever heard of garbage chunks?
this is where the error occurs
this.frames = new AnimationFrame[br.ReadInt32()];
this is the load animation
private void LoadAnimation(BinaryReaderNekki br)
{
this.frames = new AnimationFrame[br.ReadInt32()];
this.bonesIDs = new int[br.ReadInt32()];
for (int i = 0; i < this.bonesIDs.Length; i++)
{
this.bonesIDs[i] = (int)br.ReadInt16();
}
BinaryHelper Helper = new BinaryHelper(br, this.frames.Length * this.bonesIDs.Length * 6, 216);
for(int j = 0; j < this.frames.Length; j++)
{
this.frames[j] = new AnimationFrame();
this.frames[j].bonesAnimationC = new AnimatedTransformCompressed[this.bonesIDs.Length];
for(int k = 0; k < this.bonesIDs.Length; k++)
{
Half px = Half.ToHalf(Helper.ReturnShort());
Half py = Half.ToHalf(Helper.ReturnShort());
Half pz = Half.ToHalf(Helper.ReturnShort());
ushort ux = Helper.ReturnShort();
ushort uy = Helper.ReturnShort();
ushort uz = Helper.ReturnShort();
this.frames[j].bonesAnimationC[k] = new AnimatedTransformCompressed(px, py, pz, ux, uy, uz);
}
}
}```
this is how the final result looks
well, sounds like you're allocating a lot there then
yea i found the error
trying to fix it now
have you tried debugging to make sure it's the value you expect, for a start
there was an error in the code before it thats why its doing this
i am trying to fix it now
is there a simple line of code to get an input from actions and execute a line of code if it is pressed
please don't crosspost
hello, im trying to make UI have different cost amounts and show its respecting attribute that it upgardes and text and stuff, and ive got one of them, but want to add more, but the script is on tje canvas that has a variable that goes into the UI upgrade ( if this makes any sense ) so if i wanted to make more, would i have to put the script on the indivaidual ui Upgrades instead?
its only the text that changes
but now my problem is i cant take a script from my player that has the attributes.. very stumped
Ui is only there to show you values andinformations, they cant have different cost amounts as you said
wait so i cant do this
you still struggeling with the concept of oop it seems
but cant they have the same script but different variables in the inspector?
you can fetch data from somwhere to show on your ui yes, you just need to create references to the data you want to receive.
so on the same ui element you can have references to different objects/data
did you understand the idea behind SerializeField we were talking about a few days ago?
no i forgot to find that out actually
how you can have one single class(script) but have as many objects as you want from that class. see them as copies of your class. so if you create a script with a [SerializeField] that means you can change this field individually for any of your objects
so for any childs of it?
put them same script on different gameobjects and have different values in the [SerializeField]
so would i make the variables i have on cost and amout i would do a serilizedFeild?
it depends, if you want different objects yes, it is still unclear to me what you want to do
fair enough haha im not good at explaining but i will try that
im so confused nevermind
hang on
im getting a thing saying object refrence not set to an instance of an object, its about the attribute Manager, but ive put the atytribute manager in the refrence slot? like the variable thingy
ive gone back to putting on the canvas for now
nvm ive got it i accidently put serialized feild on the attribute manager
trying to dabble with a custom editor for a script i'm writing.
I want - purely for editor niceties - to be able to check a toggle and consequently set the Condition foldout to be (in)visible.
I can't seem to figure out how to make the Toggle value persist at an Editor level, without abusing something like EditorPrefs or SessionState, both of which would be pretty terrible solutions anyway.
why do i have this error?
you have an NRE in a callback for the mentioned action
there's probably a stacktrace
what is a NRE?
NullReferenceException
i don't understand anything on unity , actually infuriating
well, it's a new thing to you. that's normal, it'll take time
did you try checking the stacktrace?
if you click the error log in the console window, there's a trace at the bottom that should point to the line the NRE came from
apparently it's this line
then it can't find Dialogue on a null
did you actually put DialogueTag on a gameobject?
so there's no GameObject with that tag.
consider using serializedreferences instead of this
yeah i put the tag on a gameobjet
that, or why even use tags if you only want a Dialogue component you can just use FindAnyObjectByType
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Object.FindAnyObjectByType.html
but only use that on an object is spawned/instantiated in, otherwise it should be serialized
show
is this in scene when that FindByTag runs?
put Log and verify
or is the actual gameobject enabled when doing FindByTag
yes but it say " objet reference not set to an instance of a objet"
why not just create a direct reference to the Dialogue object and assign per inspector instead?
[SerializeField] Dialogue dialogue;
yes to what?
yes to findbytag
what about the second thing, is gameobject enabled
indeed. learning how to debug something is also good first
true
how can i see that?
sorry if it's a dumb question
is it Grayed out or the parent? in the hierarchy view
dont crosspost
yes , it's grayed
then thats why it cannot find it
FindByTag doesn't work on disabled
but anyway now you know this, just serialize the reference and link it in the inspector as suggested
okay excuse me
also post code properly using one of the Link services 👇
!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.
yeah your code is too long, rest is not visible and people won´t bother to dl it
by inspector wdym?
How do I use a camera in a public field?
wdym how do you use?
I want to be able to select a camera object in the inspector
so just drag and drop it
Well the options isnt there because idk how to add jt
do you have a camera component in the scene?
Yeah
so look here as well
#💻┃code-beginner message
2 birds with one stone heh
What's the difference between a public field and a serialized private field?
one is public, and one is private
private fields cannot be accessed from other scripts
SerializeField just exposes it in the inspector
guys i working on 2d professional game
i got mad because from 1 week i trying to apply this script which working in the first map to another maps
and its never working fine
just it work fine on the first map
i tried to solve from every where and i can't
any help ?
this the script
and these 2 photos 1 from the first map and one from second map
and here the question by the right way ☑️
these photos for the 2 maps
and this the Script what i using
A tool for sharing your source code with the world!
generally the latter is better
lilbro really double spaced it like a school essay jeez
here is the question, and the question is missing..
and its never working fine
you need to explain what not working fine means , we we dont know whats supposed/expected to happen vs whats happening
The star colors for difficulties do not work on the second map, and the condition for unlocking the next difficulty based on verifying that the previous difficulty was completed with all 3 stars does not work either.
the star colors look the same to me on the two photos
do you get any console errors, especially when changing the maps?
you should probably keep that console window docked visible
that because i working and i deleting the JSON FILE many times
but take a look now when i finished the first diffculty from the first panel
with 3 stars
i immediatly got the 3 stars colors from the easy star colors
there is a lot to debug here
and lots of sketchy string work
have you been inspecting the debugs logs?
also keep that console panel visible, as mentioned do you have errors ?
you know you can make things like difficulty enums, which is a lot safer than string
There are no errors, but I'm not getting the correct result.
thats why debugging one piece at a time should be the first step, its a lot more difficult to do so from our end because we can't directly do it
but really one thing that sounds out is you're doing alot of sketchy work with strings such as string prefabName = prefab.name + "(Clone)";
Finding objects by name is hella sketch
Do you have DDOL object somewhere ?
monliths suck man, try to split your scripts into smaller scripts focused on specific tasks it will be easier to debug
so many things in your code that need to be changed
put the Levelpanel class in a seperate script,
variables of same type can be declared on the same line,
don´t use the same if statement twice:
if (levelSystem == null)
levelSystem = FindObjectOfType<PlayerLevelSystem>();
if (levelSystem == null)
Debug.LogError("⚠️ PlayerLevelSystem غير موجود في المشهد!");
just to name a few and this is only the upper poertion of the script
that one seems fine because it tries serializefield first public and if its null tries to find runtime
and if its none found its logs error but still messy as hell
I feel like either some data isn't loading with json, or something sketchy happens but we cannot debug from here
I suspect one thing, which is the difference in scene names or keys in the two interfaces, or the names saved in JSON files.
you have to try to print out as many strings are you're trying to manipulate / use cause they're unreliable
like lol avoid doing shit like this..too much potential for something to go wrong..
if (!currentData.unlockedLevels.Contains("Easy Level " + (finishedLevel + 1) + " ~ " + (finishedLevel + 1))) currentData.unlockedLevels.Add("Easy Level " + (finishedLevel + 1) + " ~ " + (finishedLevel + 1));
thats why we use Type-Safe language to avoid crap like that
this isn't javascript
i think ima just give up for now and try to get into a call with someone later
no one is gonna get on call with you realistically
fair enough
what exactly you're not getting
the link i sent literally has a video on what to do
if you're being lazy /no reading it and want everything spoon-fed to you this isn't the place tbh..
nav provided everything you need and i even gave you copy ready code mate
why do you need a call for?
game dev is not easy and if you are not able to solve such small things you might run into bigger troubles later. take your time and read everything again
I'll get on call with you, I charge 25/hr a session. thats a bargain
25 is really cheap tbh put a 1 before
i think i'm going to pass on this bargain.
i'll re-read what you guys sent me again and try to understand , sorry for taking your time and tkx for the help
panel.star1.color = starColors.Count > 0 ? starColors[0] : Color.gray;
so I'm guessing in scene 2 this line doesn't run at all since they stay white
could be one of this in the same function if (levelSystem == null || levelSystem.data.sceneStars == null) return;
or
UpdatePanelStars not being called at all somehow
i will check
@rich adder @frail hawk it's a bit buggy but it works as intended now , tkx again
I was told that if you have for example 10,000 of the same monobehaviour game objects all calling Update, that a single manager class calling update once and iterating over a list of all 10,000 is more performant in Unity
Is there any truth to that?

not to side-step the question but generally the energy behind that question ends up down a path where you need to consider if 10,000 objects need to have update called on them (at least that frame)
there is some truth to it but really depends a lot what you're doing
Yeah fair points, the use case I was discussing at the time was units doing navigation on update moving their transforms in xyz space
why not test and profile both, you can have your answer
even empty calls of Update still have to callback to the C++ code so there that
True good point I could just profile the idea
I think it's relatively easy to use jobs for that
if you need 10,000 items you might consider going full DOTS / ECS
I have started looking into moving code over into jobs. 10,000 was an exaggeration, I was looking to have unit counts at the scale of like Total War style combat
have you seen Diplomacy is not an Option ? I believe its full dots they have thousands of units
I haven't made a made like that so you might already be on this but i'd assume it might be worth having the targets be the initial update source rather than the units? so if you have like 600 units going towards 1 target some targetinfo thing could have a reference to all those units and then tell those to update from there. or some other similar kinda methodology
Ah yeah like Flow-fields, I have looked into that as well
I haven't, Ill check that out 👀
I like the look of these screenshots, thanks
Oh wow, yeah holy hell. Reminds me of They Are Billions, but 3D
Added it to my steam wishlist now
yeah almost looks like fluids lol
they are even features on unity page . Worth considering, but you can probably start with delegating some work with Jobs and go from there
Good Lords, Fair Ladies! Today we are here to talk to you about what's under the hood of our game. At times, community members ask things like: "I've lowered the graphics settings and the performance is almost the same! How come?" or "I have an RTX 3080 and DiNaO is only giving me 40 fps! Care to explain, why?". These questions are usually follo...
Found this from the devs explaining how they use DOTS for it, useful
gotta love devs who are actually open to showcasing their workflow in development
i can say 99% of games wouldnt even dare to replicate "large army" that they showed in trailer
like the crowds in the picture
they eventually will try to fool u with 10-20 soidlers with a health bar to signify how many troops are there
this is really good
Not many games have bad enough monsters to require such an army
nah, demon lords worth it
tho they only need a warrior , a mage , a priest and an archer for that
Pretty decent crew
most devs still cater to single thread performance over multithread in an age with cpus with multicores
but DOT is very different than normal workflow tho
that is true, that is another hurdle
it really needs u to spend some times on it before u can even gets ur hand dirty and type some basic things
not exactly something you can easily get good results without knowing how to use it proper
Jobs is a nice compromise
ECS can break the mind a bit
i studied it for like 1-2 hrs only , it seemed under DOTS workflow playmode recovery is disabled?
I want to start it soon , i tried it with bullet hell and got decent results so I'm sure if you really have the time / mind to do it
after this project i suppose
what do you mean by "playmode recovery"
Jobs are nice but sometimes i just use threads because jobs have dumb limitations that i dont always want
Hello can anybody help me why i cant start a new project?
thank you
your helping me out a lott with that (:
yeah i got 6.2 instald
maybe use another path not sure if you can use the OneDrive folder
how can i make a game object restart in unity not the whole scene?
What do you mean by this?
what would a "restart" look like for this particular GameObject?
You may want to explain what you're needing to do.
save your values on awake then reset them with a method?
i want the game object like restart i mean that when you do a certain func it restart the game object like how you spawn a new object in the scene so basically it respawns the object i hope you undersand what i meant
You can spawn a prefab with Instantiate
If you mean "return it to its starting position" for example, then you would just save the starting position in a variable and make a function you can call to restore it to that position
i feel like this is an x/y problem
what exactly are you trying to achieve? a respawn system?
smth like that
and what should be reset? the position, health, etc?
the easiest is storing the values and reset with method, instantiate works but then you break references
should enemies or level state not be reset?
i assume the player dies, and needs to "respawn"
i am making an arcade flappy bird level in a big scene so i want when the player dies the game obj restart and returns everything like it was before
jusr restart the scene
Reload the scene perhaps?
yeah , ur resetting the whole game state
Should there be any persistent scene objects?
its a big scene so i want this gameobj only to restart not the whole scene
let me ask another question , what data, what things u want to keep?
Normally in a flappy bird game, the pipes are procedurally generated
I think you want more than just that one object to reset.
You want the score to reset
You want hte camera to reset
You want spawned pipes to reset
etc.
It's probably simpler to just reload the scene
which is what dalphat asked
i wont make it procedural
because the better way to reset the whole game state , if its simple singleplayer game , is to reload scene again
Keep a copy of the target's last check point (or wherever they should spawn) and reset their position (and the camera's).
jusr curious , why it is not procedual?
Level designers need money too. Just kidding.
because flappy bird is a kind of infinite game , it will go on forever
ofc players might not have the skills to keep it up to 1000 2000 or 5000
i am making an escape room game if you win you will get a score that score is needed to solve the puzzle
and winning is by passing 5 pipes
but even so, you can do procedual generations for pipes , u just need to tune the logic
I thought it was a big scene? Five pipes do not seem like many
if you die i wont make the player return bacl an play the whole level bec a simple mistake
somebody help me , i want my player moves in the direction of my camera , like if i move my camera to the left then my character's local forward moves to the left side too
oh so this is basically a minigame that you need to reset?
yeah
I'm assuming you aren't wanting to reload the scene because the player is using some sort of arcade machine in the scene. If so, just reposition objects
yeah just store whatever state you need to restore
capture the one position to another so you have the diff
i think a simply LookAt would be enough in this case
Hey guys
could work I guess. i assumed it was 2d for some reason
with keyboard usually
omg
fingers or maybe you can speech to text
hmm not bad
haha
funny?
indeed funny
ok
check the pinned messages in this chanel
Thats the total basic, I knew the basic
am i supposed to be psychic
kinda
also most people who say "i knew the basic" doesnt probably know much sorry
!learn how about this
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
esp with "how to code"
funny?
what is a float?
wrong
is a data type 
variables store types (actually more like a label to where it is in memory)
ah fck that
close
its like (public float variable = 5.3f;) ig
When I first learned programming I thought float was a verb. I was very confused until I corrected that misconception
i'd say variables have types tbh
hmm ya I could be wrong, I always thought of them a human readable way to find it where is stored in memory
oh im not disputing that part, just saying variables don't store types
instead of address x02h73h this one i s called "pies" lol
doing asm/c gives a lot of insights as to how memory works actually
godbolt is truly god's work
insane to see how variable length arrays are implemented in C (it dynamically expands the stack frame, and the variable is the address of the array instead of the array directly)
the scary part of a high-low level lang like that (mid level?)
assembly with a human touch lol
struct Foo { public int x; }
Foo a = new Foo();
a.x = 5;
Foo b = a;
b.x = 10;```
what is the value of `a` ?
mean one
i was thinking in c/c++ and answered 5...
would still be the same thing lol
kinda sad that now days though you can just paste that into google or gpt and get the answer..
well, it'd be ||{ x = 5 }||
i mean like, just straight 5
oh yeah that broke my brain a bit
not really?
welp u need extra step to change it , it is harder than classes
do you mean value-typed properties
the issue there is a reference, or lack thereof, not the actual modification
now i use struct to act as model classes to contain/deserialize data from server , something that never needed to be changed once they retrieved from server
you do realize that structs aren't semantically for immutable data though, right
but damn, i do think i violates the "16 bytes" rule
i know they are not 100% for immutable , but i believe besides from immutable , i have other valid reason to make it a struct either
being immutable doesn't have anything to do with being a struct
I want to code with my friend. Is there an easier way or a tutorial for using Plastic SCM? My friend doesn't know how to join my project.
git is industry standard, should be easier to find tutorials
Git > PlasticGarbage
its easy to use ?
yea.especially with a GUI
unitys implementation always has weird ass bugs
some operations handle better on CLI
once I merged through Github Desktop and it fucked my whole repo up
from what i learnt , struct can be faster and efficient than a class if u can use it right
and from what i learnt , there are 3 reasons to think of when trying to use struct?
- small enough or not
- having complicated types or not
- data inside are immutable or shouldnt changed too much (which is not...?)
i used this code to jump why cant i jump? https://paste.mod.gg/slpivfqnfdgg/0
A tool for sharing your source code with the world!
first off check your console window and make sure there are no errors
there is non i did
Second, you'd have to show us what this "CharacterController2D" script is, because that's not built in to Unity.
Third, make sure you actually attached your script to your character
and i did
whatever CharacterController2d is, you can find it on github with 1 google search
and there is an example controller script there
i have one
yep i think i might need to do classes instead of structs
4 dictionary + 6 string + 2 int might be big for a struct
i dont know what structs is
Looks like jumping won't work if your script doesn't detect the ground
What layers did you set as the "m_WhatIsGround" field in the inspector?
i have groundcheack
the leg of my chracter
Also where is your ground check Transform located?
Was that an aswer to the "where is the ground check Transform" question? Because that doesn't make sense as an answer to the layers question
use an empty for the ground check thats a child of the character
and where is this "leg" object located? A screenshot would help
not the character itself
it was and i didnt set a layer
Yeah you need to set the appropriate layers
groundcheck
If you set nothing, it will find nothing
yeah you need to decide what is considered "ground"
otherwise nothing is the ground and you are never grounded
how do i do that?
well im assuming you have a layer made for the ground, so simply assign everything you consider the ground to be on that layer in the inspector
You need whatever layer your ground object is to be in the mask
ohh i did
so:
- set your ground layer as WhatIsGround
- Put your ground objects in that layer
yeah m_ground or whatever has to include the ground
3 is pretty irrelevant to class vs struct
class vs struct is really just ref vs value type
a struct instance is a bundle of data
a class instance is a singular extant object
you probably have the player layer in the what is ground
and youre positive you assigned the ground layer to all of the ground?
so even the efficiency/speed boost ppl mentioned about is not a thing here😭
guys when onmouse down obj collide with another collider it dosnt click how can i fix it????????
yeah
but either way, i dont think i can use structs to contain my server data anymore, its too heavy to be a struct
@nelsonsucray muted
Reason: Too many messages in multiple channels
Duration: 29 minutes and 51 seconds
oh it is, but it shouldn't be the main concern imo
the main deciding factor should be what makes sense
someone know how to fix?
they said 30-70% boost , and it really catched my eye lol
the efficiency thing will usually follow
true
from 10 ns to 7 ns? you have better things to worry about
lol
jobs - struct, netcode - structs
hey, so just looking for a spot to ask an odd question. working on a game for a school project (2d), and for some reason when i put the inspector in debug mode, everything behaves as it should, but swapping to normal works in a completely different way
if allowed, i can post a video, but its literally exactly as described
hold on,
will fix that
im looking for a door code that when i press [E] it would open and if i press e again it would close ive been trying to find this for ages like 6 days every code that i tried it didnt work so can some oene help me
seems like you are going to have a much easier time writing something as simple as that yourself than finding existing snippets online
from what i understand, debug mode shouldnt change the execution of my scripts in any way, yet it only works properly when debug mode is open and i can actually see the values
idk how to code
its easier to learn than you think
debug, either using debug.log or the debugger and see whats actually happening. theres nothing to say here because all we see is that "something doesnt work"
figure out which line specifically doesnt work as you expect
Hi, I have a question. I'm new to this and I'd like to know if anyone knows how to use Visual Studio, or what some call Bolt. I need help moving 3D characters, as I can't find any guides.
is going into debug mode in the inspector not the "debugger"?
no
the debugger would refer to something like the visual studio debugger where you can step through code line by line
ok, I'll take a look, however im still confused why switching the debug mode on in the inspector would cause a different execution of the code
thats why you'll figure it out through debugging. figure out what line is actually behaving differently
you staring at it in the inspector wont do anything if you dont know what the code is doing
I understand that, im not worried about finding out the solution to the issue, I think I can handle that with the debugger you mentioned in VS code, just curious if you had ever seen the inspector debug mode lead to a separate outcome
vs code isnt the same as visual studio. not sure if theres a working debugger in vs code, havent used it for unity. you can also just add debug.logs around if needed.
There shouldn't be a difference between the two but either way, its your code thats running
sorry meant visual studio
what does Visual Studio have to do with anything moving in Unity
thats like saying How to use Notepad to make unity player character jump
2022 lst
wat?
ok so I made a breakpoint for the line in question, and it triggered when it shouldn't have. image may be hard to see, but airTime at the breakpoint is -153, which is less than airTimeMax which is 300. so I don't know why this line is running?
I use Bolt or Visual Script
that doesnt answer the question at all.
which line isn't running
-153 is not larger than 300 lol

i realize my breakpoint was in the wrong spot
how do you know for sure ? put a breakpoint there and check what value of airtime is at that point
so i moved it to the next line
your code editor has nothing to do with the actual code you will be writing
it doesnt impact it
and running.. Unity runs the code not VS
writing your code in visual studio is no different than writing your code in notepad
ok so after moving the breakpoint, everything seems to be working great, no issues whatsoever. leaving debug mode however, with no changes to script, results in the original issue. this is like some quantum issue. observing the values results in perfect execution, but when they're hidden, its broken
in the eyes of unity at least
there is probably something else you're not debugging correctly
it doesnt care about how you have subway surfers in the corner of your screen, all it cares is about the fancy words you wrote
simply the act of turning debug mode on in visual studio fixes the issue.
i dont know how to debug debug mode
what do you mean by pausing? the game runs with no pauses
regardless of debug mode or not
assuming no breakpoints
what debug mode ? the inspector ?
visual studio debug mode attached to unity
whats the issue happening
There are two programming methods: Visual Studio and Visual Script. I use Visual Script because I can't find the guide to move the 3D character, which is why I'm asking for help.


