#archived-code-general
1 messages · Page 25 of 1
Are you using SimpleMove or Move?
.Move
Are you applying gravity?
Yes
No idea then sorry haha
I thought maybe your character was ending up fractionally above the ground.
If it helps XD
You're calling Move twice here
You should probably avoid doing that
What is the diff between playerVelocity and charController.velocity?
I can read it better, I'm kinda dumb about that stuff
Its also nearly an exact copy of what unity has in its documentation ;-;
its for a jump
this bit
I still don't know what plaerVelocity is
but this superficially looks like bad logic to me
So its x is always 0?
ehh
actually its all right
it prevents it being called so often
it is to limit the velocity to 0
Well it's probably what's causing your issue
skylord's issue
yes
basically its saying
if the player is falling downwards
and theyre touching the ground
then set the velocity to 0
so they dont fall through the ground
personally @wanton obsidian
i would raycast
instead of using isgrounded as a check
Hhm
CharacterController.isGrounded only updates when Move is called. When using the incorrect double call to Move that brackeys likes to teach (which is what you have) it will only detect ground when you do that second call to apply gravity, so your normal movement won't be moving the controller downward to collide with ground
Basically you want this every time:
var velocity = cam.transform.TransformDirection(MovementSpeed * new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))
+ Physics.gravity * Time.deltaTime;
if (charController.isGrounded) {
velocity.y = jumpStrength;
}
charController.Move(velocity * Time.deltaTime);
combine the gravity with your input and call Move one time per Update and it will work correctly
the double call to move is, yeah
... I got it from the unity documentation...
the extra call to move? yes
huh, it is in the docs. well that's no good
although the docs do grab the isGrounded property before the first call to Move so it does still use the value from that second call which is correct
rip
i just tried to make a light2d variable and unity told me i was using outdated something or other and replaced it with this
is there no way to make this shorter?
are u using 2D urp?
What did you do before and what exactly unity told you? Also, unity can't replace your code.
ye
there was a popup saying do you want to update this old file or whatever
If you use the correct namespace, you can just type Light2D.
oh i just had to add the using at the top
How can I avoid empty pass-through constructors in my subclasses?
using UnityEngine.Rendering.Universal;
// ...
class Foo : MonoBehaviour {
public Light2D light;
In 2D? You can cast a polygon
IIRC
like from this ball
and in the shape of that light
and get all objects inside that all the way down
Ah, I'd probably cast a number of individual rays
or whichever way its facing
no but i also want to get objects behind the other objects
ok
oh so do i just use it like a trigger?
You can use GetPath and SetPath to modify the points
ah yeah that sounds good
I'd use OverlapCollider personally
but you can use it like a trigger if you want
Personally I prefer to just ask for a list of results
yeah overlap collider will work perfectly
what do you mean by empty pass-through constructors here?
all it does is call the base constructor, doesn't do any work or set any variables.
You can't if the parent class has an explicit constructor.
not sure what the question is - do you just want to not have to write the constructor line in your subclasses?
yes
they want an implicit constructor when the base class has an explicit one.
At least that's my understanding
what is the constructor for this
It's a limitation of C#, the constructor needs to be done explicitly.
Inferred constructors only happen when they have no parameters.
bruh why do these docs not mention a constructor
oh im dumb nvm
for the path of polygoncollider2d, would the coordinates of each point be in world space or object spacce
would this work or do i need to create the PolygonCollider2D as a gameobject
if i used polygoncollider2d.createprimitive to create the triangle, what orientation would it be in
the function doesnt have a rotation thingy built in
Because you can't create unity components with constructor.
How should I do this? I haven’t used unity in a little while
Components can only exist on gameObjects, so you use AddComponent to instantiate components.
Anyone know how I can implement the cameras rotation into this to make sure the character moves the way the camera's facing. I thought I had it correctly but its not working like it used to
How do I add my playerVelocity into the character move to keep from using two controller.Move's
hi i need help how do i make
hi i need help how do i make a harry potter style wand ?
with a modeling program and following basic modeling tutorials
not really a code question tho
oo ok
cs charController.Move((cam.transform.right * horizontal + this.transform.forward * vertical + playerVelocity) * Time.deltaTime);
Just add the playerVelocity vector I guess
You need to create a component, yeah
Can we change the default speaker mode in script? I tried AudioSettings.speakerMode - but that just returns the active mode
question I have enabled full stack debugging and yet I get this message :
"A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details."
here are the settings in projects settings
hey I'm looking for a way to compare 2 colours, currently im doing it via math.distance(), but this is providing some odd results, is there a better way to do this?
Main Menu > Jobs > Leak Detection > Full Stack Traces
thank you, i will try it but I am not using DOTS
Native collections are part of the dots tech stack
I see thank you
Where are you using a native collection ?
Debug.Log not showing in Editor mode
It depends on what you mean with compare. Because if you mean that in respect to how alike 2 colors are for a human, then you can look at color theory for that.
https://en.wikipedia.org/wiki/CIE_1931_color_space or some other ones, there are multiple theories about it.
If you mean the RGB values, you could just do what you already do. It's unclear to me what odd results currently entail.
Then that part of the code ia not being called at all @urban owl
fascinating, thanks so much!
Happy to help 
it is called, I sure
How are you sure?
It is possible you turned off the logs in the console window
There should be 3 toggles in it for logs warnings and errors
Does anyone know how to use TMPro sprite assets via C#/script?
In the inspector you can use <sprite index=1> easily to display the sprite.
As of now the asset I am using takes a string and then sets a TMPro text to that string, but I cannot input sprite index=1> as a string.
OK, thank you
Do you see the debugs now?
it's showing

Unity Job System 1 dimentional Quadtree Brainstorming
Hello,
I'm having a really weird bug in my game 🤔 (really annoying and really hard to reproduce...)
Basically (removing everything that is irrelevant), I have two scripts : Warrior and Game_manager.
Game_manager instanciates a warrior in Start and calls the Warrior.activateMove() method in the first update.
Warrior initializes some variables in Start and uses these variables in activateMove()
public class Game_manager : MonoBehaviour
{
public GameObject prefabWarrior;
private GameObject warrior;
private bool firstUpdate = false;
private void Start()
{
warrior = Instanciate(prefabWarrior, ...);
}
private void Update()
{
if(firstUpdate)
{
firstUpdate = false;
warrior.GetComponent<Warrior>().activateMove();
}
}
}
public class Warrior : MonoBehaviour
{
private GameObject moveArrows;
private void Start()
{
moveArrows = transform.GetChild(0).GetChild(2).gameObject;
}
public void activateMove()
{
moveArrows.SetActive(true);
}
}
My problem is that rarely (about 5% of the time), in the built game (maybe it's a coincidence but I've never had that bug in the editor), the game starts, the warrior is instanciated correctly but then Warrior.activateMove() is called before Warrior.Start() 🧐 (I know this because of some logs I added, the Warrior.Start() wasn't called when the bug occured)
Therefore I get an "Object reference is not set to an instance of an object" error and nothing works...
Warriors are only instantiated in Game_manager.Start() and activateMove() is only called in Game_manager.Update()
I'm guessing there's something I don't understand in the order in which Unity calls the Start and Update methods but then I don't get why it happens so rarely. Any idea why this happens and how I could fix it?
chatbot thinks you should use awake method instead of start
Probably because update is not guaranteed to happen after start
Yeah maybe using Awake would fix it
I already have other things in Awake
That's a good idea though!
Then use a boolean rather than firstUpdate
I'll try and come back in a few days if the bugs occurs again 😆
Thanks!
IDK if I'm right, but I assume there is no guarantee that Start happends before Update. It happends after Awake
Why AI
it s usefull xd
Stop relying on ChatGPT to give you an answer
It's going to tell you that because awake is obviously where initialization happends half the time, but not here
^
@dense vessel Can't you just instantiate and then call your move method after, all in the same method?
I've never had any problem like that though 🤔
Maybe because it's the Start of an object that was instanciated in the Start of another object?
Or, create a coroutine which contains the spawn method, then it yields a frame, and then it moves?
Then it's all contained in one method basically.
That would not fix the issue since I need the Warrior.Start() to be called before Warrior.activateMove()
The coroutine one works for that
Awake and start happen at the same frame
unless you don't enable it at initialisation time
So I would start a coroutine in Game_manager.Start() and the coroutine would instanciate the warrior, yield a frame and then activateMove() ?
Basically, yes
And Warrior.Start() would be guaranteed to be called in that frame?
But your warrior's Start method stuff should happen in an Awake anyway
The update of one Mono is not guaranteed to run after the start of another. The best solution is to have your own Init method in the Warrior. Instantite in manager start, get the component and call init method on it
So you might aswell change that
Because it's able to find your gameobject in an awake
Ooh that's probably the easiest solution. Thanks!
Like, if you do your Unity stuff properly, you don't even have to bother waiting a frame for stuff
If you do your initialization in awake and behaviour in start, it basically never goes wrong
Oh true, I thought I had other stuff in Awake but that was another script 😅
Thanks a lot for all these solutions!
So the Awake of an object instanciated in Game_manager.Start() is guaranteed to be called before Game_manager.Update() ?
Im not sure that its guaranteed
Awake sure is early enough to fire before any update but I dont think there is an actull guarantee
Well I'll do the custom start solution then, this way I'm 100% sure 😄
The only guarantee is for a individual mono
Yep, its the cleanest and easiest way
Yes, it is
I just don't know if Start is guaranteed to happen before it
I think it depends on when you instantiate. Like if you instantiate late instead of when Unity boots it probably varies
I assume it's before Update then
Ok. But I still prefer Uri's method. This way I don't rely on Unity's stuff, I'm 100% sure it works and I understand what I'm doing 😄
He's right though. The update of your manager is not guaranteed to happen after your Warrior's Start (and awake??) method. That's why it's so confusing
People usually work around it by making an init method and passing required data in there, since awake and start don't take parameters
But if moving is a recurring thing, you can totally just call that manually
Threadly reminder
Well they can but then it won't be an Unity function anymore so it'll just be like any other function
So in theory you could have your own method called Start with parameters and call that yourself, though that's a bit confusing probably so maybe not the best practice
Because Unity doesn't know what values/references the parameters have 🙃
That's probably also why there's not an init method build in in general
If you feel like it you could implement a custom instantiate method that calls init for you, kind of how c#'s Activator works: https://learn.microsoft.com/en-us/dotnet/api/system.activator.createinstance?view=net-7.0#system-activator-createinstance(system-type-system-object())
I'd advise not to use chatGPT
Also any questions you get if you use that code, you may not ask since the code is AI generated (#📖┃code-of-conduct)
I have a strange issue that is happening at Runtime and not through any errors or spitting anything into my Debug.log. It could be code related but may be a setting issue somewhere.
I'm not very experienced with Unity, but I do have two scenes that work fine when I'm in the Editor and click Play. But when I do a Build, my first Scene with 2 basic UI buttons on a menu does not work. It works fine in the editor but not on the build. I have to Ctrl+Alt+Del each time. Is there something minor I'm missing here? Or do you know if this is a code issue I need to debug?
It's a New 2D Project, the first button is to Play the game and just opens up Scene 2, and the second button is coded to Exit the Application.
I'm having a problem with chunk generation for my 2D TopDown game. The further away from the center the player moves, the further away the chunks generate exponentially.
This results in chunks not generating on the player.
I'm pretty sure the problem is in the highlighted part of the code as the chunks still generate on the correct coordinates, just not correctly around the player.
Thanks in advance.
ChatGPT is very solid, but please don't use them to develop your application unless you understand why it does something. Also, ChatGPT can be very wrong.
So, unless you understand the code he just generated, I advice finding a way to make your script without AI
^
It can be a great learning tool, but that's mainly because video tutorials are so overrated and common and ChatGPT won't give you gazillion video tutorials like google :D Can be hilariously wrong also, so you really need to know something about the subject already.
For example, whilst this what the bot said isn't wrong, it might not be what you want since it's always overriding velocity and then you cannot "properly" use physics
Is there a well known thing in Unity to check when something works fine in the Editor but not at Runtime?
I wouldnt script in the first place
Elaborate?
You can use Preprocessor directives to make things run in only the editor, but I don't know if that's probably not what you mean
@woeful leaf I have two scenes that work fine when I'm in the Editor and click Play. But when I do a Build, my first Scene with 2 basic UI buttons on a menu does not work. It works fine in the editor but not on the build. I have to Ctrl+Alt+Del each time. Is there something minor I'm missing here? Or do you know if this is a code issue I need to debug?
It's a New 2D Project, the first button is to Play the game and just opens up Scene 2, and the second button is coded to Exit the Application.
True, it is a great learning tool when you want to try something new. Except people don't learn from it, they just copy paste whatever ChatGPT gives them, and ask proceed to go to #💻┃code-beginner to ask "Why doesn't this work??? 😿 ".
I used it to learn React last week
But I actually wrote stuff myself after it was explained
@woeful leaf I was thinking it could be related to the layers I have the background image on and the buttons, but then it shouldn't work in the Editor either if that were the case.
Both buttons don't work or?
Both buttons works in the Editor but after I compile and Run the build nothing works, it gets to Screen 0 which is my Game Menu screen, but nothing works and I have to Ctrl+Alt+Del out each time
Can you show the code?
Do you think it could be an issue with my code? Because I wasn't sure if it was my code or a setting in Unity I'm missing.
Still getting use to Unity
Well there's a difference between exiting the application and exiting the editor
using UI;
public class Quit : MenuButton
{
public override void OnClick()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
So if you only have the former then it won't actually do anything in the build
The latter should work though
// Start is called before the first frame update
public Button playButton;
public Button quitButton;
void Start()
{
playButton.onClick.AddListener(GoToGame);
quitButton.onClick.AddListener(ExitGame);
}
private void GoToGame()
{
SceneManager.LoadScene(1);
}
private void ExitGame()
{
Application.Quit();
}```
Sorry, first time trying to post code in here
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
(Edit the previous instead of posting it again)
Should be under your ESC key
Thank you!
That's the related code I have for those two buttons
The buttons are assigned in the inspector I assume?
It has to be on separate lines like the example gives
Yes
Assuming you don't use them in other scripts through that script, you should make it [SerializeField] private instead of public
That's not why it doesn't work though
Finally got.. thanks
You've no errors, correct?
Those buttons would only appear on that menu
Like any errors
Correct.. no errors
Actually, my Exit Game button doesn't work in the Editor mode, but I assume that was because I was running in Editor and why I was trying to test it in the Build Run
@woeful leaf
Eventho this doesn t say much it should help explain my situation
Could you slap this code on it instead?
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
Sure..I'm open to suggestions
cpp flashbacks
@thin aurora Yeah definitely not copy-paste material. But especially for programming can be quite good and actually sometimes gives better results than google. Like I don't know if it has eaten whole github or what, but sometimes if you ask about some things like behavior of specific API it gives you answers which definitely are not directly available from google.
Like I don't know if it has eaten whole github or what
I'd not be surprised
@woeful leaf Nice... that make it quit the game in the Editor now
It does now, yes. Doesn't work in Run.. just tested it.. I also noticed that the Button highlights are no working when I mouse over them in the Build Run. They work find in the Editor
Did you try this?
Reading it now
Interesting.. it was set to the Old method and when I changed it to both.. Unity Crashed..
first time I've seen it crash like that
Welp reboot it and see if it changed
If it hasn't change it back again and pray it doesn't crash kek
Yeah.. It wanted me to reboot a bug so it's doing that right now
report*
It saved it as both
Now to test it
Nope.. same as before.. I can move the mouse cursor around but it's almost like the game is locked up
Could you just like put some text in the main menu that just increases an int and displays it to see if it runs?
Just put in Start()?
No update so you can see that it keeps running
Ah right
I am so confused rn,
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
Debug.Log($"{x} : {z}");
I made a new project, put this into it, why does z return -1 when no key is pressed?
This is being called every frame in update, but in 3 different projects I put this into, z always = -1 when its nothing is being pressed
It was my sim steering wheel messing it up ^ god damnit
Kind of a broader question. Is inheritance used to manage multiple levels with the same script or is there another way to do it in Unity?
Scriptable objects
If its the exact same code different variable values, use scriptable objects
Great thank you
I'm having some trouble with yield returning a method. It worked fine for other methods, but for some reason this one won't start.
Code for context: https://hatebin.com/sulellohyp (see the "This part fails" comment)
Problem description:
- When the player clicks on a move button, the method
OnClickMoveButton(index)is executed and a Coroutine is started to handle their input. - If they select everything correctly, the methods
HideMovePanel()andMoveSelectionOver()get called. HideMovePanel()is executed succesfully. It hides the move panel, and when debugging, breakpoints get hit.MoveSelectionOver()is not executed succesfully. For some reason, the method doesn't even get executed. Breakpoints aren't hit, nothing happens.
I was wondering whether anyone knows why this might happen / sees something I've missed.
Oh, and something else that's weird; if I change the order of the methods (first MoveSelectionOver() and then HideMovePanel()) MoveSelectionOver() does get executed. However I really don't see how HideMovePanel() could stop MoveSelectionOver()'s execution.
Any errors?
Also what is TurnController.instance.StartTurn(selectedMoves) exactly
Try yield return StartCoroutine(MoveSelectionOver());
You aren't calling MoveSelectionOver correctly
I also assume your gonna have the same problem with yield return TurnController.instance.StartTurn(selectedMoves);
In the past / for other methods I've never needed to do that, but I'll try it out
Was the coroutine already initialized?
You can do that if you already called it, but thats not how you call a coroutine in unity, so unless you call it somewhere first that won't work
Updated the hatebin link. At the bottom of the file I included the TurnController.StartTurn() method.
No errors, just... nothing.
Like you could do
Coroutine moveOverRoutine = StartCoroutine(MoveSelectionOver());
yield return moveOverRoutine;
I've always done it like this. Are there differences in execution?
private Method 1 {
StartCoroutine(Method 2());
}
IEnumerator Method 2 {
yield return null;
}
yes you are returning null in Method2, you are not starting another coroutine
But you start the coroutine by doing StartCoroutine(Method 2());
You aren't doing that in your code, you might call StartCoroutine(ProcessInput(index));
but you dont have any for the others, you are returning an unstarted coroutine
how do i deal with Editor Code that needs to be on a ScriptableObject but the SO cant have a reference to UnityEditor Assembly cause i want it to work in build? Specifically i want to use [OnOpenAsset] to open a custom editor window
Don't think thats possible unless unity has a dll
its a unity feature, not a c# feature
I see. I'll do some more research and try your suggestion. Thanks!
Its going to work, everytime you call a coroutine and want the code inside to run, you need to do StartCoroutine first so unity knows
Thats also a feature unity has, not c#
Your code
private Method1() {
StartCoroutine(Method2());
}
IEnumerator Method2() {
yield return Method3();
}
IEnumerator Method3() {
yield return null;
}
how it should be
private Method1() {
StartCoroutine(Method2());
}
IEnumerator Method2() {
yield return StartCoroutine(Method3());
}
IEnumerator Method3() {
yield return null;
}
I thought thanks to the yield returns the methods were automatically "chained" in one big Coroutine. That's how it's worked for me previously. But thanks for the detailed explanation!
greetings. when i check if two lists have any intersecting elements, it returns true, but when I to get those elements, it seems to return null.
They will "chain", you just need to start the next one, you can't call it like a normal function, they aren't functions
Although that doesn't explain why it worked if I switched HideMovePanel() and MoveSelectionOver()... Any idea about that?
This is the most un descriptive thing i have read here
Yeah, I think that was my error of thought.
wym
Do they both contain null? 😅
like instead of
no shot, they log player names
HideMovePanel();
yield return MoveSelectionOver();
you did
yield return MoveSelectionOver();
HideMovePanel();
like that?
Yes, exactly
If thats the case, you have an error in HideMovePanel
if (List1.Intersect(List2).Any())
{
var variable = List1.Intersect(List2);
Debug.Log(variable);
}
Still weird the next coroutine would be called though without StartCoroutine
No errors logged, not even warnings
logs null
Are you sure MoveSelectionOver is getting called?
Like add a debug to it, so when it gets called it logs it
Don't just think its doing it
Aaaah nevermind I got the problem!
Again, does not help us
hmm what i can do is have my custom window in MyAssembly.Editor and the SO in MyAssembly. Then with InitializeOnLoad i can subscribe to an event triggered from my SO OnOpenAsset. This just seems like its not the right way
what is the problem then
im showing the code that has an issue
In HideMovePanel I set the gameobject to inactive. That's the same gameobject the script is attached to. Now that I do yield return StartCoroutine(MoveSelectionOver()) I get an error "Coroutine couldn't be started because the the game object 'MoveButtons' is inactive!"
You are not showing all your code
You are just showing yourself logging it
Not the values going into it
alright i'll look into it
it returns an ienumerable<string> for me
Oh
and I convert it to string
string list, still the same
you cant log it like that
var variable = List1.Intersect(List2); isnt a string
its a IEnumerable<string>
i use tostring()
not in that code you dont
IEnumerable<string> variable = List1.Intersect(List2);
foreach(var killmenow in variable)
Debug.log(killmenow);
i've been coding for less than a year
this is legit my first time using ienum
You are getting the string value of the IEnumerable
the IEnumerable has multiple values in it
not just one like your trying to do
Even if it only has one, its a list type
So you will have to loop through it
Or get the first value
IEnumerable[pos]
I gave you the code above
and apologies
This will work
will it stop loop when isWalking isn't true anymore? if not, then how to stop this loop when isWalking isn't true?
Everyone needs to start somewhere, that's totally fair. However, next time you ask a question on either this Discord or somewhere else online I recommend you follow this step-by-step guide from StackOverflow: https://stackoverflow.com/questions/ask (you can see it on the right under "Step 1: Draft your question"). It'll make it a lot easier for us to help you.
aight <3
It should, although due to the WaitForSeconds you have a delay of 0-1 seconds until it actually stops. Also, I recommend doing this with an Animator instead of scripting: https://docs.unity3d.com/Manual/class-Animator.html
paste ur code
i don't know how to use animator, it's to hard but i will try
nvm, i will try animator
Actually
I ont wanna
I was gonna fix it, but you should rewrite that
Movement should not be done through a ienumerator
I'd recommend a YouTube tutorial. Easier that way :^)
can animator change sprites in SpriteRenderer?
Also, that will have delays of atleast half a second
Im pretty sure
nvm actually
I have no idea
yes
then how to do it?
actually i dont think you can
Correct me if im wrong
but I dont think so
Try recording an animation where u change the sprite
huh ok
Its easy
Create a new animation, hit the record button, drag the new sprite in
i dont know if it will log it or not but i dont see why it wouldnt
how to change entry? i want to connect it to idle
Right click on the on idle, hit set default layer
Then make a bool parameter
make a transition from idle to walk when that bool is true, walk to idle when its false
oh i did it
and set the bool to your iswalkin value
Get a reference to your animator, animator.SetBool("walking", isWalking);
in your update ^
if the dash is not connected to anything, can i still play it via script?
Yes
cool
animator.Play("Dash");
Make a transition going back to idle though
after exit time for example
or however long you want, or could just do in code animator.Play("Idle"); when you wanna go back
I recommend trying to keep it clean, animators start to get confusing very fast
i have animator, right? now i can play dash with it like you did?
Yes
cool
make a parameter in your animator for walking and switch between idle and walk
with transitions
How to do multithreading?
and set that parameter to your isWalking
by creating multiple threads?
yeah but how do I communicate with the main thread
i can't even call instantiate
Because its on a different thread
So
Well how do I improve chunk generation performance then
Essentially a different program
It lags a lot
Chunk loading and saving
Only generate chunks around the player
ungenerate and save the ones the player isnt near
how every game ever does it
Tf do you think I'm doing?
lmao
It still lags
Good
Mainly when you walk
I just grab chunks from a dictionary
Maybe learn about things before trying to implement them
That would help
And when someone is trying to explain it to you
Don't act rude
Why do you need different threads then
No game uses other threads for that lol
not a single one
I can 100% confirm that
because its not possible
The game might run on multiple threads
But the generation part is all in 1 thread
yeah so i figured i could dedicate a thread to chunk generation and do the rest on others
But i can't run things like instantiate on that thread
Which i kinda need
Make your own engine then
Unity doesn't exactly have multithreading as far as I know
You are going off of unitys thread
The second you do that
You lose all unity functions
gameobject not really, DOTS entities yes
When you work asynchronously in Unity, it just delegates the tasks in a custom state machine that still works synchronously because Unity methods must work on the main thread
Well shit
Thanks, now I get why DOTS is a nice feature 🙃
I tried coroutines it's not working great
Running different threads in unity would honestly be worse
I never looked into it either way
Yea hopefully they keep improving it
Unity works with c#'s async-await pattern. Unity 2023 has good support for it
Don't use a Coroutine
Entities uses the Job system, which can be used without Entities.
But Unity2023 is in alpha
i was gonna say
So use with caution
either that or use UniTask package as that has the same features as what 2023 has with Awaitable
Jobs has been considered production ready for a while and does actual multithreading
burst
As is Burst. Neither require Entities.
well the issue is what is actually costing performance, working out the generation or actually spawning it
you could use jobs to work out the generation and then mainthread spawn it (with pooling)
But why
Just disable stuff the player cant see
and enable what they can see
Its easy to implement, and good for performance
yeah sure theres other ways as well
My dude you are literally speaking out of your ass. It depends on what his actuall perf problem is. Pooling might not fix it.
Pooling vs instantiating objects
Pooling is faster everytime lol
Its most certanly not a best solution for everything
Adding pooling is always better, even if it's unecessary because pooling is not going to make your performance worse
did i say that
dont come at me like that
when ur being a dumbass
Read what i said
read the entire convo before that
We are talking about spawning in objects
There are 2 ways, instantiating, or pooling
The true Stackoverflow experience, there is always somebody to disagree with you in here
I just find it funny he said im talking out of my ass
It's a toxic way to learn, but learn we shall
when its proven what i said, and its proven what he said aint true
no there isn't
Good way to let out some steam instead of bashing my irl coworkers too
im in school for cis
Coding for me is simple, just when u hear people talk about it they talking about like 500 random things at a time
Nvm you guys can continue being dumb 
Literally unity has made a post about this
Pooling is faster
always
you're missing the point
pooling is a tradeoff of memory - if you had a very large game you may not be able to just pool everything
Its not OMG GAME CHANGER performance for all, but when your making a game every little bit counts
Thats not what im saying
how do you serialize Transform in Netcode?
public void giveServerRpc(Transform obj)
{
orgP = obj.position;
orgR = obj.rotation;
CarriedObject = obj;
coName = obj.gameObject.GetComponent<item>().name;
CarriedObject.GetComponent<MeshCollider>().enabled = false;
}
Im talking about his issue
And he is the one that brung up in general
Im still talking about for world generation
And still, even if its not the issue
There is always a way where people can totally twist the subject and turn a simple question into a massive debate
you optimize the problems, not fabrications
Its still better than instatiating
Ok but is it not better?
Im saying it is always performance wise better, can you say that is false?
Because that is all i said
entirely dependant on the usage
I didnt say its perfect for everyone in every situation
Never have i said that or anything towards that
I dont get why you guys wanna argue just to argue
Also its not situation dependent, performance wise will be better
Ceratone: Your code is shit
Ceratone: cant help ya
👀
Situation dependent on how much of a difference
Because everybody thinks they're better than everyone. It's the programmer dopamine and it's cheaper than coffee.
Read above that
I was tryna explain something to him and he was tryna be rude about it
i dont get how that has anything to do w now
This isn't really going anywhere
If someone can prove what im saying is wrong ill shutup
but everyone keeps saying im wrong, then tries to say im saying something im not saying
This is such a good distraction from work tho
That is fair
🍿
This server is banging today, so much shit code and dumb arguments
I haven't done shit work-wise
Ive literally been just tryna help people here
I don't disagree with you
people keep trying to argue with me for literally no reason, google your arguement before you say it
because what im saying has been proven
my animation doesn't work, i will send you screenshot, just give me a sec
Ceratone: Your code is shit
Ceratone: cant help ya
?
feel like you may need a timeout
Cool
Good thing your not staff then
Because ive literally been helping people for the past 2-3 hours
and im still tryna help someone
he is just trying to help and he just told the truth about this guy's code. i don't think timeout will be fair, he helped me for like 1 hour
and you keep tryna bring up shit that everyone let go
Just ignore them
If any of them can make a game that runs ill consider their opinions
I have lmao, yall keep bring it back up
Do the animations work?
You realize this whole shit show started because somebody argued against him and worded it like a moron, right? If you and another guy didn't join a side this would have stopped 12 minutes ago, so stop playing the blame game.
literally
it plays fine in preview but it doesnt play in actual game
Show your animator
idk why dash changed to dash 0
Do you care how it works? or do you just want it to work
Because you can do it a lot easier with just the animator
it's an animator
idk man
Ok
Do you see the parameters tab?
thx for help
yes
make a bool called isWalking
Right click idle, click make transition drag to walk
and do same thing back, from walk to idle
ok
Turn off has exit time for both, on the transition idle -> walk, set condition to isWalking = true
like this?
wait
yes
like that
On the one going from idle -> walk, toggle off the has exit time
and add a condition where isWalking = true
@woeful leaf Just wanted to let you know I never did get a Text incrementor added, but I figured out my problem from earlier. For some reason I had deleted the MainCamera and EventSystem from my Scene 0. After adding those back in, it fixed my runtime issue. Thanks for the help.
and same for walk -> idle, but isWalking = false
i dont see
Click the transition line
i dont see "has exit time"
ok
the white line going from them
If that's the case why did it work in the editor?
Or did you never rebuilld it?
done
for both?
Hmm don't know enough about Unity to really answer that. But it was working fine in the Editor.
how pooling
are you really that petty
yes?
Did you save the scene when the editor had an eventsystem and camera, and then build it?
wait a sec it takes me time to search it
huh
give me a sec
It could have been using Scene 1's EventSystem and Camera for the Editor as I had them both loaded. I suppose in a Runtime, only 1 scene is loaded at a time?
bro
and toggle off hasexittime
Usually they're not in a DoNotDestroyOnLoad so that shoudn't be the problem



@minor sigil when i generate a chunk i log it in a dictionary so i don't have to re-instantiate it
is that what you're talking about
Yes, then set it to unactive if the player can't see it/isnt near it
Yeah I'm already doing that
I'm just experiencing lag spikes when activating/instantiating them
For best performance, if you disagree with this i stg, only render graphics that you can see
Is it different events for activating/instantiating?
Like does it only instantiate when its being generated for first time?
and once its instantiated, it goes to a pool and gets called .setactive from there?
are you sure?
Wouldn't i have to pool them anyway? Would suck if you unloaded a chunk and your builds disappeared
what
Exactly
there is a warning
You did something else then
its rly not
you click the white line
there is a boolean box
called Has Exit time
uncheck it
Under that there is a conditions box
hit the + button, select isWalking, set value to true or false
Is instantiating more laggy than setting active?
Not noticeabley, no
yeah but when i uncheck it there are warning and when i check it back warnings stop
Do you loop through the dictionary everytime?
The entire dictionary, not just the ones you want
No, i grab it by a Vector2
So you use coords?
add the condition
it makes it go away
i did it
I just round off the position of the player to that of a chunk, so yeah i use coords
The chunks are logged with their positions
What's that :(
talking to him
oh
how to stop the Walk animation?
Yeah
The one I've replied to
And the only thing you do is set it to active? like the only line you have is gameObject.setactive(true/false);?
Yes
idk what is der
wait a sec
listen
i will let you help steve
i think you are overwhelmed
In your update funtion add, animator.SetBool("isWalking", isWalking);
I think other stuff is being called
lag isn't just caused by 1 thing
Especially if your not looping through something
Hard to say without looking at the code, best I could say, not trying to be rude, but code more efficient , think of a more efficient way to do what your trying to do. all apart of coding
all i want to do is stop and animation, is there something like animator.Stop() or something?
I would watch a yt video to learn more about animators
There is a .stop
but like
nvm i fixed
Animations are usually done in animator, you can control it by code, but most of it is done in the actual animator
ugh. you're.
Wait sorry no I'm calling a Chunk.Unload() function
What is done in that?
Which has two lines
Also
how many chunks are you trying to load at a time
That could also be the issue
gameobject.setactive(false)
Also lods
And isloaded = false
its just a lag spike right? not constant lag
And are you loading the new one before unloading the old one?
It's 2(renderdistance)²
guys where to ask about material issues ?
Spike
Unload first
art channels
thx
I don't know what exactly is causing it since i dont have your code, but if its a spike its something being called during those functions
Check everything that is called when a new chunk is loaded and unloaded
Is there a gameobject.isactive thing
yes
oh okay
how the fuck am i supposed to stop animation
.selfActive
Please watch a video or listen to me
Why not ChatGPT
chatgpt is only good if you know how to code
Because its not copy and paste ready
It gives you an idea of how to do it, not copy and paste tho
ChatGPT is refusing huge code blocks
It just freezes when i give it a huge code block
lol i never tried sending it code
Yeah I mean that's what I do
It can debug stuff
Ah
I'd not advise ChatGPT
I find chatgpt very sketchy
Its owned by microsoft, but why were they hiding that they were the owners of it?
i mean what do you have to lose
They take a lot of ur info
It being against the rules
a shit ton of ur info
...
theyre partners
well you really just need an OpenAI account
You're not gonna get hacked relax
not owned by microsoft
They are under the microsoft corp
owned by elon musk
false
"Don't answer questions with AI"
not
"Don't ask AI for help"
Yeah but if you apply the "fix" of the AI and then ask why it still doesn't work then you violate the rule
sorry man
i dont think you understand
many many things use azure
thats like saying
I know but microsoft has a say in what they do
If they are partners
more like friends
They are openai top investor
openai is its own company that microsoft invests into
???
Not actually owners
i dont think you know what owning means
But with the money they have into them
Not actually owner
and i dont wanna get political
but when you have that much money into something
your gonna have a say
Just because they sponsor it doesn't mean you own it
Probably best to stick to coding
Do you guys use vscode, vs or smth else entirely
vscode
VS
notepad?
If your IDE is not autocompleting code
or underlining errors, please configure it:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code*
• JetBrains Rider
• Other/None
*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.
Same
they have multiple lead investors MS is only one of them
IDE's are for babies
ew
So its not like they are just throwing money at openai for free
If they do that it genuinely might compete with Google
See
The search engine, not Google as a whole
I dont think anything will compete with google
everyone knows its shit
but everyone still uses it
not everyone, but most
it will be terrible for search engines actually, results are useless unless sources can be cited chatGPT can not provide sources
ChatGPT can't even do math
chatgpt they could literally give u a personalized assistant for your computer
also this is all off topic
SiriGPT
That is true
Right now no, but it def would be easy to add

ChatGPT tried to tell me 0.2 repeating+ 0.8 repeating = 1
why would you use it for that
I mean, it'll tell you the right thing if you make sure it understands what you want or are doing first.
like i am not for chatGPT but that is a poster child case of wrong tool for the job
It knows +=
We are a LONG way for adding chatgpt to search engines though
Right now it is using data from 2021 i think?
we would have to make it constantly learn new things
like, everytime something is uploaded to the internet
it would know
It thinks queen elizabeth is alive
which is honestly a security issue
And you can't do that while it's online. For obvious reasons lol
WAIT LMAO
YEAH
Please move the conversation elsewhere before the mod comes back to hit you on your head
I tried too everyone came back here
Is there a good way to start a shell command asynchronously, and pipe the output back to unity as it happens?
i want to talk with someone about the ads with mediation in unity and technically my problem isnt with scripting, who should i contact?
maybe just ask in #archived-unity-gaming-services
I still have no idea how to do that i'll have to look into it, thank you !
hi i used this code [Header("Keybinds")] public KeyCode jumpKey = KeyCode.Space; to make it so i jump on the space bar but the code isint jumping here is the link to the code https://codeshare.io/WdVy78
add some logging figure out what the code is actually doing vs what you expect it to do
confirm its actually getting into the condition to jump
ohh someone just change the things in the link ill paste it into a new link where people cant edit it ig
and howd i do that?
bruh dont click that link no more
Don't cross post
Mathf.PerlinNoise keeps printing the same value
are you adjusting its inputs, it called with the same coord as before gives the same output
sorry it took some time in the beginner so i just typer here but ill go back to beginner thingy
Patience is key :p
And if it does take a while feel free to bump it up in the same chat, but don't move it to another chat
If you're worried about it getting buried, you can always create a thread
oke i wasent sure if that was allowed ive been iin other discords where you shoundt bumb
bruh someone does it again
ig ill just put the code in here so people cant edit
Just use a paste site that people cannot edit
I mean it's in the #854851968446365696 ¯_(ツ)_/¯
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
well it looks like readyToJump is false and isnt set to true initially
private bool readyToJump = true; try that
Would this be a bad way to do thing? Like should it be a switch case or should it be something else?
switch (gameObject.tag)
{
case "Bad":
switch (collision.gameObject.tag)
{
case "Bad":
ScoreUI.OnAnswer(ScoreUI.AnswerType.Correct, passwordDrop.good++);
break;
case "Good":
ScoreUI.OnAnswer(ScoreUI.AnswerType.Incorrect, passwordDrop.bad++);
break;
}
break;
case "Good":
switch (collision.gameObject.tag)
{
case "Bad":
ScoreUI.OnAnswer(ScoreUI.AnswerType.Incorrect, passwordDrop.bad++);
break;
case "Good":
ScoreUI.OnAnswer(ScoreUI.AnswerType.Correct, passwordDrop.good++);
break;
}
break;
}
Basically you can drop an item into a box, which can be good or bad, and it has to match the good or bad of the box
Hence the double switch cases
bool isCorrect = gameObject.tag == collision.gameObject.tag;
ScoreUI.OnAnswer(isCorrect? ScoreUI.AnswerType.Correct:ScoreUI.AnswerType.Incorrect, isCorrect? passwordDrop.good++:passwordDrop.bad++);
that's what I would do. No need for the switch case at all
it's bad in the way you shouldnt compare tags like that
Why?
Due to the .CompareTag reason?
yup
bool isCorrect = gameObject.CompareTag(collision.gameObject.tag);
ScoreUI.OnAnswer(isCorrect ? ScoreUI.AnswerType.Correct : ScoreUI.AnswerType.Incorrect,
isCorrect ? passwordDrop.good++ : passwordDrop.bad++);
i would also take the switch over double nesting a ternary for readability
I just focus on avoiding comparing hardcoded strings
but this type of cases in a real codebase i would almost always handle with interfaces and TryGetComponent
I'd just pass in the isCorrect bool to OnAnswer and avoid the ternary altogether
let OnAnswer handle the inner logic, since they both rely on the same isCorrect bool
OnAnswer doesn't accept bool though
It's an enum with 4 cases
But they do not need to be in the Switch case in this case
the pattern I see here is just that if the gameObject.tag and collision.gameObject tag matches, then it'll always use Correct, and add good
since it's the same for both "Bad" and "Good" tags, OnAnswer doesnt really need to be passed in all that logic
it's going to do A when the tags match, and do B when they don't match.
I suppose yeah, thanks for the insight
you're welcome. this was a fun exercise
And it is confusing that your tag "Bad" and passwordDrop.bad does not seems to relevant
Rename one or both
passwordDrop.bad should probably be passwordDrop.incorrect
Yeah still working on the naming of these things
Also renaming tag is messy, that's another reason why you should not use tags
That's fair but it's not a giant project or anything, so I think it's fine to use it here
I'm probably like 80% done if not more
I don't really have the time to make a sophisticated system for it
Sorry for taking a million years, yes the inputs are definitely changing
I know this isn't necessarily a coding problem but how do I add starts to the background the scale when I zoom in or out? I need it to be dynamic because I can't just have thousands of stars on a scene at any moment
there is no "Is Walking" and "Isn't Walking" in console, also animations doesn't play. what i did wrong?
looks like you are not ever calling Animation
then how to call it?
oh wait
i think i know how
im fuckin dumb
thx man
also does someone know how to adjust thumbstick dead zone? i changed it in project settings but it doesnt really change anything
im using new input system
ok
What’s the best way to learn vr coding
Time and effort
And just begin with the basics
So the pins in #💻┃code-beginner will do
Il trying to say like where can I start learning it yk
Because when I type on YouTube etc not many come up 🤣
Do you know the basics of Unity and C#?
Yas
Well google around for courses and such I suppose
Just start messing about in a project see what works and what doesn't
Doing is the best way to learn
Can we change the default speaker mode in script? I tried AudioSettings.speakerMode - but that just returns the active mode