#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 750 of 1

crimson canopy
#

oh awesome

rocky canyon
#

then i use a little distance check that way any offsets i use are scaled accordingly..

(the distance text is offset 1/2 a unit above the object @ 1 unit away...)

#

using that simple conversion i can keep the offset looking good no matter how far from teh camera the tracked object is

#

so if i were 2 units away it'd be more like .25unit above the object.
if i were 10 units away it'd be like .05 units above the object.

that was really the only issue i had was the indicator would look differently depending on how far from teh camera it was.. so basically just normalized it

crimson canopy
#

@rich adder exposing my math rustiness, whats the best way to find this last number, since i dont want it to be a fraction directly relative to the distance between the two points, i just want it to be close to the player + a couple units

wintry quarry
#

I would just not add an entry to the dictionary in the first place until it has a value greater than 0

drowsy flare
#

I have a problem where I don't get the colors as expected when I draw a line using LineRenderer.
If I use: public Color color1; and select a color using the color picker in the editor, the line doesn't show up.
If I use: public Color color1 = Color.red; the line shows up and is red.

Any ideas?

wintry quarry
rich adder
drowsy flare
#

You are probably right, I just don't see how

wintry quarry
rich adder
# crimson canopy alr lemme try

this is kinda pesudo code not literal.. screenpos would be the Screen.Width along with some calculations of getting the size of the indicator etc

wintry quarry
#

Also make sure you save the prefab.

crimson canopy
drowsy flare
rich adder
# crimson canopy yea ik its just a different method so im gonna try it

mhm I can give a more practical example when I'm at the pc soon, a bit uncomfortable now to do now I'm on the go.
I'm sure you research on this problem there's plenty of modes done the way I suggest (this is how I also done it before)
Never should I needed physics for it / colliders.
that won't scale well especially if you ever decide to expand the viewport/change the size

drowsy flare
#

@wintry quarry Btw, I got it working yesterday with drawing the lines, worked out really pretty. Now I'm building it further with more lines between more objects ๐Ÿ˜›

#

That's why I need the color picker

wintry quarry
drowsy flare
#

Hmm when debugging I actually get the correct colors (?):
Colors: RGBA(1.000, 0.000, 0.000, 0.000) color2: RGBA(0.519, 0.000, 0.000, 0.000)

#

Wait

#

That's fully transparent

#

HAHA

wintry quarry
#

ah- so you were just setting a transparent color in the inspector

drowsy flare
#

Yeah, didn't know it defaulted to fully transparent

#

Okay, looks super good now

#

Thanks again

drowsy flare
tacit prism
#

back to my previous question

i was a dumbass and added a space to the statename in the editor, making it a completely different item i was trying to call, i love being an idiot

rich adder
tacit prism
#

imm quite the professional at messing things up in editor

rich adder
#

ehh strings very common to mess them up.. If you have multiple places you need it I usually go for a const at least its only changed in 1 spot (can only mess up once and not multiple times / worrying to update each one separate)

shell sorrel
shell sorrel
# tacit prism this

so work with a lot of designers and less technical people and i will often just do a .Trim on strings from input

#

and sometimes also a ToLower

#

deals with any white space on either side of it

#

other options are if there is a finate amount of them just use a Enum

rich adder
shell sorrel
#

that way in editor its a dropdown

shell sorrel
tender onyx
#

Hey y'all. Working on a rougelike and need a little help with some UI work. I'm shooting for a Risk of Rain 2 style system to display powerups you've grabbed so it's easier for the player to know what all effects they have. I've seen some "close" guides for it, but nothing quite like what I'm looking for.

Any of y'all have some good resources (videos, forums, etc.) that could help? TIA

rich adder
tender onyx
rich adder
#

what specific features are you looking for ? what is missing in the resources you looked at ? and so on

tardy lagoon
#

i cant figure what is wrong with my code

rich adder
#

look carefully on how you structured this line

tardy lagoon
#

something with transform but ive been looking at it for 5 min now and just feel dumb

cosmic dagger
cosmic dagger
#

That's always a good start . . .

rich adder
cosmic dagger
#

Though, you can definitely spot this one . . .

polar acorn
cosmic dagger
#

Just look at every character on the error line . . .

tardy lagoon
#

idk what yall mean ig im just stupit but i cant figure it out

polar acorn
tardy lagoon
#

not really, flipping it up ig x is like forword and y is it

#

up

#

idk man im looking at tut

grand snow
#

taps sign

polar acorn
tardy lagoon
#

go down one

polar acorn
#

transform.localScale.y is a number, so let's just substitute a random number for it, like seven. If you saw a math problem that looked like:
-1 7

Would that make sense to you?

tardy lagoon
#

idk 6

polar acorn
rich adder
#

there is nothing in between, how would you know (to add subtrace, etc.)

grand snow
#

someone plz just tell them its invalid syntax

polar acorn
#

so has the compiler

#

and so has the tutorial they copied this from without thinking

grand snow
#

ah the old "i swear i did exactly what the tutorial said"

polar acorn
#

And I figured by asking a patently absurd math question they'd see where the problem is and go double check that exact spot

rich adder
#

oh this is from a tutorial too ? that gives you even more easier solution to just compare the two

polar acorn
#

But patently absurd math problems only work on people who have ever looked at a math problem before

#

so I guess that doesn't work any more

rich adder
tardy lagoon
#

In this video, we're looking at animation basics in Unity. We'll explore how to set up walk and idle animations, and how to flip our sprite from left to right. This video works as a standalone, but is also the second video in a beginner-friendly series where we create an Action RPG in the style of Zelda: A Link to the Past.

Next time we'll get...

โ–ถ Play video
slender nymph
# tardy lagoon

now compare that line, character by character, with what you have

polar acorn
# tardy lagoon
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 197
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2025-10-16
rich adder
#

hey only 197 between 3 years, not bad average

polar acorn
#

Wait a minute you're the same person I've Counter'd at last time

#

You really need to actually look at the code you're copying. Or, you know, actually take a second of effort to understand it

rich adder
#

glad I grew up with those games where you compare two images to find the mismatched/difference in items, comes to good use ๐Ÿ’ช

slender nymph
#

"They're the same picture" - 197 people since 2022-07-19

tardy lagoon
#

what the comma i added that and there is still a problem

slender nymph
#

what is the new problem

polar acorn
tardy lagoon
slender nymph
#

check your spelling

rich adder
#

jfc

tardy lagoon
#

idk what refrnce im missing

rich adder
polar acorn
slender nymph
polar acorn
#

compare it to the thing literally right next to it

#

and see what's different

#

I, honestly, cannot understand how you don't see this

#

The only explanation is that you literally are not looking

rich adder
#

I was gonna say troll post but then I tell myself Hanlon's razor...

polar acorn
#

Please, for everyone's sake, take half a second to look at the thing that's underlined in bright red

#

and think "Hm... this didn't happen last time I typed this. I wonder what the difference is?"

#

This is a channel for programming. Not Sesame Street.

rich adder
# tardy lagoon idk what refrnce im missing

another interesting thing... when you type and use the . operator.. you get suggestions on valid things that are part of it, put it to use and select those items... don't just blindly copy something, take the time to see whats happening as you write these things.
understanding basic concepts like . access can go a long way if you're trying to make something as complex as a game..

warm jetty
#

Hey, I'm very new to this kind of stuff and I've run into a problem twice. I'm attaching a script to a button to increase a value on click, but the only options I'm getting are 'No Function' or MonoBehaviour with the drop-down menu only containing a string option.

slender nymph
warm jetty
#

Thank you ๐Ÿ™

limpid sundial
#

Hi guys. I have around 1.2k frames (at most) on a single 2d character. for a much cleaner game making is it better to separate them? (ie. walking North, Flying North,SE,W or just dump them in the sprite renderer and remember their count? I'm planning on using them on a small scale 2d multiplayer rpg. around 5-10 ppl?

sour fulcrum
prime cobalt
#

Does anyone have any idea how this could be null considering it checks if any of the values are null?

polar acorn
#

Oh, wait, that one is just outside the others

prime cobalt
#

First check is for if it's null

polar acorn
#

I thought they were allin a row

#

but some of them are nested

prime cobalt
#

I just forgot that I had a nested check for the playerPawn as well when I made the check for it

polar acorn
#

Are you sure that's the line the error is on? Show the stack trace

limpid sundial
ivory bobcat
sour fulcrum
#

Is whatever running this code the right instance of it?

prime cobalt
# polar acorn Are you sure that's the line the error is on? Show the stack trace

NullReferenceException: Object reference not set to an instance of an object
GridController.HandlePlayerTileSelection (UnityEngine.Vector3 inputMousePos, CharacterPawn inputPlayer, Mouse inputMouse, System.Boolean overRidePreviousPos) (at Assets/Scripts/Grid/GridController.cs:184)
GameHandler.Update () (at Assets/Scripts/GameHandler.cs:110)

polar acorn
prime cobalt
polar acorn
#

You put all your null checks on a completely unrelated line

#

So either GameHandler.instance or GameHandler.instance.playerCursor is null

prime cobalt
#

Hmm ok

#

Ah ok I managed to fix it, thanks!

wintry quarry
sonic dome
#

why is the gravity so bad

#

its the default 9.81

#

and i try to play around with the values here

#

but it still feels like my player is a feather

#

also i checked something why is it that the cube falls faster than the cylinder?

hot wadi
#

Are u attaching the script the cylinder?

rough granite
# sonic dome why is the gravity so bad

Well going by the values here one could assume you are a 30kg mass with a jump force of 400N of course you're going to feel as light as a feather (this is assuming you wrote your code nicely) cause at that rate you would have an initial velocity of 13m/s or 46 ish km/h which is insane.

Went on a tangent, for why the cube falling faster no clue realistically it shouldn't

hot wadi
#

The mass does not affect the falling speed

rough granite
#

That's why i said i had no clue why the cube fell faster

rough granite
naive pawn
# sonic dome but it still feels like my player is a feather

this is pretty typical
most platformers/games have quite high gravity compared to irl to make it feel nicer, and there also might be a higher gravity when falling (a higher "down gravity")

try looking up the platformer toolkit by gmtk to play around with some values there

naive pawn
rough granite
rough granite
naive pawn
#

this is an impulse force, gravity is a continuous force

#

you can't just subtract them directly i don't think

rough granite
#

Fair point

naive pawn
#

if it's applied as an Impulse force then it's not actually force, it's momentum

bronze fossil
#

Hello,

I have a game concept in my mind and I have never used unity or any engine before or have made any games before
I wanted to ask for your opinion

this game has some unique features such as:

  1. Needs to have an always on top transparent window
  2. Needs to be able to change desktop wallpaper of the user(the wallpaper will be dynamic as well like in rainmeter)
  3. Needs to be an app that should run on "statup"

can this be feasible in unity?
if not if possible please provide me any info about what would fit my requirement

currently i wanna make it in windows 11
thank you very much

sour fulcrum
#

have you googled any of these

hot wadi
#

Sounds like something u can do with Winform. Unity don't have much control over the system like this I'm afraid

hot wadi
#

Winform uses C#

rough granite
sonic dome
#

isnt it w = mg

rough granite
# sonic dome why would that be

Cause gravity doesn't play favourites the acceleration you fall from gravity no matter how heavy you are is always 9.81m/s^2 (assuming you are on earth)

sonic dome
#

hmm interesting

#

okay now im at the point of making guns

#

now when i shoot i tried make a rigidbody bullet

#

but when i shoot it at high speed it just bypasses the collisions

#

assuming its faster than the game can calcuate the collision

#

but bullets are supposed to be fast

#

is rb not a good idea?

rough granite
#

I would just recommend using a raycast

#

And dont create an actual bullet object

sonic dome
#

how do games use rb or they dont at all?

rough granite
#

For what bullets?

sonic dome
#

yes

rough granite
# sonic dome yes

They would change the collision type from discrete to continuous iirc

sonic dome
#

oo let me try that

rough granite
#

But again if you want realistic speed bullets us a raycast

sonic dome
#

wouldnt it be more realsitc when phys is being simulated

sonic dome
sour fulcrum
sonic dome
#

that makes sense

rough granite
# sonic dome wouldnt it be more realsitc when phys is being simulated

For the bullet speed? Im sure you could just find the distance traveled and using a set speed for that bullet say (ruudementary numbers) a range of 500m at a velocity of 1000m/s would make it half a second travel time so you just check half a second after they click if the user has a hitbox at the point the raycast first found

#

Though at that rate you'd need to account for gravity when checking so you'd add (1/2)-9.8*{TravelTime}^2 to the height

spark vault
#

Anyone willing to answer a few noob questions on a voice chat? Mostly just very basic stuff so i can understand the concepts without getting into details.. but specifically looking for someone with some experience with Server-Host-Client experience. (Like Server handles the verification and HP, Damage calculations, then sends broadcast back to Clients.. haha im gettin into the weeds here, I guess I need 2 people, one that understand Hierarchy for basic questions in unity, and one that maybe has exp with a multiplayer game, and the Authority for stuff.. idk im new, any help appreciated, thanks!

rough granite
spark vault
#

It's kinda a stretch for the multiplayer ask, but i still have questions on like.. "where do you store the GameManager.cs or EventManager.cs in the project? Make a Main Scene that remains open to hold these and then other scenes reference it or do you just add it to all scenes? "

keen dew
rough granite
brisk ibex
#

Does anyone have any advice on how I can generate text onto a texture2d in the dumbest way possible?

I don't want to use any of the UI stuff if possible.

hot wadi
sour fulcrum
rough granite
sour fulcrum
#

..yes

#

eg. if any of this uses 3d rendering

#

winform is far less enticing, no?

rough granite
#

Kinda sounds like they wanna make wallpaper engine 2.0 :/

sour fulcrum
#

which is fine if they want to

rough granite
#

Totally

rough granite
sonic dome
#

im back to unity after like 4 years this feels refreashing

spark vault
#

Then answer my questions on VC lol, I feel like im over-analyzing the basics

hot wadi
sour fulcrum
#

i didn't assume anything

sour fulcrum
spark vault
# sour fulcrum no vc's on this server, sorry

I know but there is options, if anyone is willing.. im new and just want to ask some basic questions because I did the whole 'watch 15261326 tutorials, and learn nothing' I don't wanna do spaghetti code, just have some basic questions.. maybe ill go to fiver and look for unity dev ha

bronze fossil
sour fulcrum
#

ai is shit

bronze fossil
sour fulcrum
#

also be sure to ask about doing it in c# too

bronze fossil
#

ooo

sour fulcrum
#

unity uses c# so stuff done in c# can be done via unity

bronze fossil
#

ooo i c

bronze fossil
# rough granite Kinda sounds like they wanna make wallpaper engine 2.0 :/

you see i want to do something like this

so when you are using your pc on a programmed time certain entity comes to your screen
you have an mechanism/interactive way of acquiring this entity
when you acquire this entity you can set it in your background wallpaper
and you know it's that type of cozy kinda game

ok so the entities are in 3d
and the wallpaper is also live so the entities can move in it

#

so the window should be transparent and always on top for when the entities come
and on the desktop page the window will be behind the folders

rough granite
bronze fossil
#

so i go with unity ig?

spark vault
#

i feel like a lot of people will feel like that's a virus unless you make reference to the old Tomogachii lol

rough granite
#

well it'll be a better choice than trying to make a game from nothing

bronze fossil
#

alright thanks

spark vault
rough granite
bronze fossil
rough granite
#

but do you mean like they character (say a cat) would be behind everything like in the wallpaper or it would be ontop of your applications?

spark vault
bronze fossil
rough granite
#

ah so like a two window setup where one would be like Bongo cats tiny window with the gifts and the other like wallpaper engines wallpapers?

rough granite
#

i mean im not sure how to do it myself but i am fairly certain it is possible

bronze fossil
sonic dome
#

is onNetworkSpawn still a thing?

#

cuz i cant find it

hexed terrace
#

(and check the docs for the version you're using)

sonic dome
#

yea found it thanks

midnight plover
sonic dome
#

understood

#

thanks

lost moss
sonic dome
#

How can i set a custom spawn location to my network manager in netcode?

midnight plover
sonic dome
#

i somewhat did but was hoping for a simple alt

#

but anyways ill do it later atp

#

where does this audio come from i thought it was the GlobalVol

midnight plover
#

Wild guess, you are creating two cameras somewhere. Just serach for the component AudioListener as it says

sonic dome
#

ooo its the main cameraaaaaaa

#

yea

#

thanks

#

Okay now the million dollar question i searched online but it seems like I just do the normal instanciate to add objects to the scene but for some reason it doesn't seem to work

#

Why could that be

#

And yea the object i try to add has the network object script

midnight plover
#

#1390346492019212368 might be a better palce to ask if its about the whole setup of the game and not a specific code part ๐Ÿ™‚

sonic dome
#

Why does it have to be a post channel ๐Ÿฅน

limpid thistle
#

The Pivot of my object in the prefab and in the scene are correct, but when i try to rotate it with this code:

                rb.AddTorque(Vector3.forward * randomZTorque);```
It starts rotating from the feet, instead of from the pivot. why?
robust schooner
#

never mind - didn't read whole way through

limpid thistle
#

this does fix it so the pivot is at the feet, but doesnt fix the issue that i want it to rotate from the center haha

#

do i have to import the meshes into blender and reset the pivot?

robust schooner
#

if you want to rotate it from a different pivot, you could parent it to an empty

#

then rotate the empty

limpid thistle
#

thats already what im doing, but it doesnt work

midnight plover
#

Top left of your scene view, it says "center"

limpid thistle
#

already put it in pivot mode, doesnt fix a thing

midnight plover
#

Can you show, where your pivot mode is placing the indicators of the object you want to rotate? But yeh, might not be a code question at all

limpid thistle
#

at the feet, like i said in my post

#

Also tried placing the mesh location at -1, so the pivot is here, but this does not work in runtime

midnight plover
#

everything tied to bones is not just easily moved around because the bones and animator control where the mesh should go. #๐Ÿ’ปโ”ƒunity-talk might be a better place to ask, as this is not a code problem but a setup problem

elder canyon
#

If I need to add forces to my character in random directions. Should I go with Character controller and program my own force generations or scrap Character controller and go with rigidbody?

What's the best solution for a 3d character? would it be a character controller or a rigidbody?

scarlet pasture
#
        {
            Debug.Log("Ich fahre jetzt los!");
            var pos = this.transform.position.x;
            pos += Speed * Time.deltaTime;
            this.transform.position = pos; 
        }```
#

Hey why cant i use that?

#

i dont find the Problem.

midnight plover
#

Please explain a bit more, what is not working or what prevents you from using it? where are you firing this code?

slender nymph
limpid thistle
limpid thistle
scarlet pasture
limpid thistle
elder canyon
limpid thistle
limpid thistle
scarlet pasture
#

thank u

elder canyon
#

I feel like adding custom force methods to character controller would be more natural?

limpid thistle
#

yes it is, but then you will have to create your own custom force methods, which is easier said then done

#

and AI is not great with making anything physics based

elder canyon
#

It's pretty easy

midnight plover
radiant voidBOT
midnight plover
#

Feels like you should have gotten errors while typing those lines

scarlet pasture
#

i dit but i didnt understand why

#

but know i know again evertime i want change the Position i need to give him a new Vector

#

and i have another problem, somtimes my code dont work. Can u guys help me pls

#
{
    // mach was
}
naive pawn
#

that's also a really vague question

#

!ask

radiant voidBOT
# naive pawn !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

naive pawn
#

you have you give details on how exactly it isn't working

#

is there an error? is it not doing anything at all? is it doing it incorrectly? etc

rocky canyon
#

like approximation

naive pawn
#

you could also define an epsilon
like Mathf.Abs(-2 - x) < 0.1f

rocky canyon
#

im sure theres cleaner ways (ie โ˜๏ธ ).. but just pointing out the difficulty of hitting a number exactly

scarlet pasture
#
            {
                Debug.Log("Hey!");
                start = false; 
            } ``` Thank u i did it like that, i saw a Code Syntax in a Forum
rocky canyon
#

may want to also include the "false" into the condition itself

#

tha way when it triggers it does it things and waits for something else to reset the flag..

#

that way ur code doesn't run it more than once at a time

scarlet pasture
#

a u mean a bool befor the Movement run, if yes i did that

rocky canyon
#

if(inRange && start)

#

yea

tulip stag
#

Is it a bad idea to add a listener to an event inside of the very script it is "firing" from?
I have an event that, when fired, other scripts do their things but there are some methods in this script that also always get called whenever I have to fire them. What I'm doing rn is

    MyEvent?.Invoke();
    MyMethod1();
    MyMethod2();
          (multiple times in the script)

Should I be doing

  public static Event Action MyEvent;
  OnEnable
  {
      Subscribe to that very event that is in this script => MyMethod1, MyMethod2;
  }
  OnDisable
  {
      Unsubscribe and stuff
  }
rocky canyon
#

well if its gated somewhere else thats fine too.. just saying.. cuz that condition could run alot if it isn't controlled somehow

#

-1.9, -1.98, -1.99, -2 <- liek that would run it 4 times (say if u only wanted it to run once when the range is detected)

rocky canyon
#

i do it all the time

naive pawn
#

consider if the MyMethod1/MyMethod2 would change over the course of runtime, if so then you'd be using events sure

tulip stag
#

For some reason my brain is telling me listeners to events in the same script are a bad idea but I can't tell exactly why

rocky canyon
#

as long as u subscribe and unsubscribe when u need to doesn't really matter if its in the same class or not

tulip stag
#

Fair enough

#

Thanks!

elder canyon
#

Is isGrounded is bugged for CharacterController?

naive pawn
#

no, make sure you're adding gravity even while on the ground

elder canyon
#

I feel like the only other way, I can know if the character is on the ground is by doing a ray cast

naive pawn
#

how it works is basically it checks if it hit the ground the previous Move
if it didn't move vertically, it'd basically be hovering above the ground and it'd consider that not grounded

elder canyon
#

I'm applying a slight gravity, while it is still on the ground. But It's still not working reliably

naive pawn
#

perhaps show your movement

#

!code

radiant voidBOT
elder canyon
#

If I do slight movement, isGrounded works. But that is not the solution

#

Should I just go with a linetrace system, instead of this buggy "IsGrounded" ?

#

@naive pawn

naive pawn
#

linetrace? do you mean raycast

naive pawn
hot wadi
elder canyon
naive pawn
#

it expects 1 move call per frame

rocky canyon
#

just combine ur vectors into (1) and pass that iinto the move.

elder canyon
#

If that's the case, shoudlnt it work if I do not apply any movement? But it's still not working

rocky canyon
#
Move(finalVector * time.deltaTime);```
elder canyon
#

Oh you're right @naive pawn .
It's working now
Tnx

#

How did you figure this out

naive pawn
naive pawn
rocky canyon
# hot wadi U should keep the velocity zero when it's grounded instead of negative value ```...
        private void ApplyGravity()
        {
            if (characterController.isGrounded)
            {
                if (gravitySim < playerSettings.gravity)
                    gravitySim = playerSettings.gravity;
            }
            else
            {
                gravitySim += playerSettings.gravity * Time.deltaTime;
                gravitySim = Mathf.Clamp(gravitySim, playerSettings.maxFallSpeed, 0f);
            }
        }``` its common to use a *small* downward vector when grounded... (constant)
and a accumulative downward vector when in the air so u accelerate when falling
naive pawn
rocky canyon
#

i think thats the first thing i learned ^ bout 4 years ago

#
            finalVector =
                (groundVector * finalSpeed) +
                (airVector * playerSettings.airSpeed) +
                (Vector3.up * gravitySim);

            if (jump.magnitude > playerSettings.jumpMagn)
                finalVector += jump;

            characterController.Move(finalVector * Time.deltaTime);```
#

really helped learning Vectors as well as a byproduct

naive pawn
#

(though, since i work in 2d, i haven't used the charactercontroller myself at all. i know the 1 move per frame rule purely from helping here lmao)

rocky canyon
#

combining them.. (modifying pieces of them).. removing some of it etc

naive pawn
#

and the isGrounded thing

rocky canyon
rocky canyon
#

i use it all the time (without any additional ground checks)

#

altho there is a bit of an issue i found. and its probably b/c of what u said earlier Chris..

I had to end up running two groundChecks.. for some reason to get my "Landed" sfx to play..

hot wadi
rocky canyon
#

teh first one couples with the movement code.. and the last one is reassurance i guess.. (its the only way to get my Landing sound to not be sporadic and inconsistent)

rocky canyon
#

i would imagine that 0 could cause weird issues

#

could.. i just dont know how off-hand

naive pawn
rocky canyon
#

^ yea there ya go

#

u could be ever so slightly above the ground.. and the check would be lying

#

something something.. maybe skinwidth

naive pawn
#

you would be 0 units above the ground but not actually touching the ground (which gravity would make you do)

hot wadi
#

About that, I stopped using cc ground check and just go with a small offset spherecast

rocky canyon
#

totally acceptable.. ^ see thats what i meant

naive pawn
#

iirc, CC doesn't do physics-esque collision checks
it checks if the previous Move wouldve hit anything

#

that's why you need to move downwards to detect the ground

#

since if you don't move downwards you technically don't touch the ground

rocky canyon
#

i like array groundcheck w/ raycasts

#

can use multiple rays to get a more advanced ground-check

#

if these rays are grounded but these arent.. i can tell that ur standing on a ledge..

#

in a certain direction

#

same w/ slopes and whatnot

elder canyon
rocky canyon
#

u don't 4 would be plenty

#

or 5 if u want one in the center

#

๐Ÿ“Œ note: theres dozens of ways to do Ground Checks.. Raycast is just a single one..

#

you can do overlapspheres, checkspheres, spherecasts, boxcasts, regular trigger colliders. so on and so on

elder canyon
#

Thanks!

sonic dome
#
    void Update()
    {
        if (!IsOwner)
        {
            return;
        }

        _moveDirection = move.action.ReadValue<Vector3>();
        Debug.Log(_moveDirection);
        airDragHandler();
        sprintHandler();
    }
#

why is _moveDirection always 0 0 0

naive pawn
#

also why is it a Vector3

sonic dome
#

it was working like a sec ago

naive pawn
#

oh i guess vertical movement, huh

cosmic dagger
naive pawn
#

check the input debugger to make sure input is being recieved

sonic dome
#

i did set all that up

sonic dome
naive pawn
#

ohhhh no swizzling

naive pawn
sonic dome
#

where is input system

naive pawn
#

in general, perhaps?

sonic dome
#

nop[e

naive pawn
#

oh, in analysis, apparently

#

...you couldn't just look through each category? lol

sonic dome
#

yea found it

sonic dome
naive pawn
#

that's not what i'm trying to get them to look at, no

sonic dome
#

weird

naive pawn
#

so input is being received, but the action isn't forwarding it - that narrows it down a lot

#

make sure the action is enabled

sonic dome
#

hows that done

naive pawn
#

if the input action asset is set as the default, it'll be enabled

#

if not, you'll have to enable it yourself

hot wadi
#

U did not set it in OnEnable(), did u?

haughty forge
#

How to code for checkpoints and reset car if it flipped or out of the track?

naive pawn
#

those are quite a few different questions

rocky canyon
#

check them sequentially

naive pawn
#

break them down into smaller problems, and google the simpler problems to start

#

saving checkpoints, checking rotation, making bounds, etc

haughty forge
#

Ok

sonic dome
#

but it was working perfect like an hour ago

naive pawn
#

and is it set as the default asset

sonic dome
#

๐Ÿ˜ญ

sonic dome
naive pawn
#

that's not what i asked, no

#

is the inputactionasset it's in set as the default asset for the project

sonic dome
#

it is empty rn

#

let me add it

naive pawn
#

you need to have the action enabled, which can be done manually, or by setting it as the default asset

sonic dome
#

it worked "_"

#

thanks so much

hot wadi
naive pawn
still ingot
#

Are there any good resources for how to create a custom inspector for beginners. I have been trying but encounter odd errors each time. More noticeably when changing my script to derive from the Editor or EditorWindow i get an error?

#

I have even added a assembly reference to try and fix the error but no luck. What am I doing wrong?

grand snow
#

Very strange, UnityEditor.Editor is correct

rich adder
# still ingot

I think you dont even need the assembly referenced there, did you click definition on Editor class? where does it take you

grand snow
#

the core apis are always avaliable to all assemblies so yea not required

still ingot
#

What is the correct process to set it up. I'm really lost right now because I have been trying for a week now and doom scrolling for youtube tutorials

rich adder
still ingot
rich adder
#

weird.. is the error present in Unity ?

#

could be VS buggin out ?

still ingot
#

I will try to regenerate the script to see if anything changes but idk

rich adder
#

maybe not related or maybe it is but tbh unless you have a specific reason to use asdef I would not use it, just overcomplicates the project structure

still ingot
#

I have no errors in unity so it might just be visual studio

rich adder
#

yeah its weird maybe you can try regen project files, this is one of the reasons I stuck with VSC on windows as well, I had VS bug out like that for no dam reason

stray fog
#

Hi,
Has anyone worked extensively with KCC?

I am building a CharacterController Class, Player Class and Camera class. I am trying to build a full body controller. Basically I have gotten the movement correctly and mouse look around but the camera won't stay infront of the head, I will be implementing a IK solution for spine and head movement at later stage until I have the base fundemental of player controller working.

using UnityEngine;

public class PlayerCamera : MonoBehaviour
{
    private Transform _followTransform;
    private float _verticalAngle;
    private float _horizontalAngle;
    private Vector3 _offsetFromFollow;

    public void SetFollowTransform(Transform t)
    {
        _followTransform = t;
        // Calculate and store the initial offset from the follow transform
        _offsetFromFollow = transform.position - t.position;
    }

    public void UpdateWithInput(float deltaTime, Vector3 rotationInput)
    {
        if (_followTransform == null) return;

        _horizontalAngle += rotationInput.x;
        _verticalAngle -= rotationInput.y;
        _verticalAngle = Mathf.Clamp(_verticalAngle, -89f, 89f);

        // Apply rotation
        transform.rotation = Quaternion.Euler(_verticalAngle, _horizontalAngle, 0f);
        // Maintain initial offset from the follow transform (eye level)
        transform.position = _followTransform.position + _offsetFromFollow;
    }
}

PlayerCamera

still ingot
grand snow
rich adder
#

yeah try doing : UnityEditor.Editor

still ingot
rich adder
still ingot
#

Omg it was the ASMDEF the entire time haha!

rich adder
#

huh isnt that something... I just tried it with a test Asmdef but it worked fine

teal ice
#

I have a problem whith the player input component โ€ฆ
How can i fix it ?

rich adder
#

they are recommending you make your own basically

#

cause the project wide conflicts with the purpose of PlayerInput

#

with System wide you don't need PlayerInput and vice versa

tulip stag
#
        var loader = new WWW(url);
        yield return loader;
        output.text = loader.text;
    }```
#

This is the snippet in the package

#
        var outputText = "";
        for (int i = 0; i < urlArr.Length; i++) {
            var loader = new WWW(urlArr[i]);
            yield return loader;
            outputText += loader.text;
        }
        output.text = outputText;
    }```
#

This one too

rocky rock
#

what do people recommend using to unit test async methods?
I was using await Awaitable.NextFrameAsync() but since a recent TestRunner update, all tests using that method just stalls forever

rich adder
# tulip stag ``` private IEnumerator OutputRoutine(string url) { var loader = new ...

something like this basically

private IEnumerator OutputRoutine(string url)
{
    using (UnityWebRequest request = UnityWebRequest.Get(url))
    {
        yield return request.SendWebRequest();

        if (request.result != UnityWebRequest.Result.Success)
        {
            Debug.LogError(request.error);
            output.text = "Error: " + request.error;
        }
        else
        {
            output.text = request.downloadHandler.text;
        }
    }
}```
rich adder
tulip stag
#

You just fed my family for thr forseeable future

#

I'll call the wife, job is secured, food will be on the table tonight

rich adder
#

hehe yay my work in red cross paid off

#

i shouldve probably inversed and put Success as first if statements lol

#

oh well you can always do it that way if you want but no biggie

tender mirage
#

Does anyone know how to remove a specified entry in a table?
lets say i want to loop through a table and remove that specific index if conditions are met.

if you post an answer, do only post the keyword for what i need

naive pawn
rocky rock
#

switching to await Task.Delay(0); now

grand snow
#

Good lordy that's not the solution

#

I use unitask because it actually works in edit mode properly

tender mirage
rich adder
#

don't add it in the first place?

#

pseudoish

var myList = new List<GameObject>();
foreach (var go in gameobjects){
if(go.CompareTag("myTag")) myList.Add(go);
}
tender mirage
# rich adder pseudoish ```cs var myList = new List<GameObject>(); foreach (var go in gameobj...

i see,

i just made this myself as well. Altough i've only ever used the keyword list to grab Resource folder items.

private void UpdateTargetCount()
{
    //
    Transform[] Children = GetComponentsInChildren<Transform>();

    print(Children.Length - 1);

    TargetCount = Children.Length;

    for (int i = 0; i < Children.Length; i += 1)
    {
        if (!Children[i].CompareTag("Target"))
        {
            TargetCount -= 1;
        }
    }

    


}
rich adder
#

if it works though you're fine.. though imo the keeping a sepeare list can come in handy if you need to do something specifically with the Targets

#

otherwise you need to iterate this list again and do the same thing

tender mirage
#

the only thing i'm remotely proud of is my versitile shake script

#

this one is especially a mes since i've been experimenting alot if certain features. honestly it's pretty bad going through it

#

sometimes

rich adder
#

btw you can also do

  foreach (Transform child in transform){
//stuff
        }```
<https://docs.unity3d.com/ScriptReference/Transform.html>
#

and skip GetComponentsInChildren

tender mirage
#

wait that works too?

#

That's. i don't know how to feel about it.

#

it seems amazing. and easy but also kinda cheesy lol.

rich adder
#

yea idk skips an extra GetComponentsInChildren prob

#

first time I've seeni += 1 in a for loop lol

#

well maybe not in a while at least

#

are these objects added at runtime ? you can also keep track of them when you do that.
otherwise I just use the inspector and put them in there

naive pawn
#

it also probably skips the array allocation

#

and uhh i think it's ordered by child order? whereas GetComponents would be ordered by internal id

tender mirage
rocky rock
# grand snow Good lordy that's not the solution

why not? despite what I'm reading, my tests are passing, so it makes me believe it actually does run async
what about Task.Yield() instead?
Also I just realized Awaitable.NextFrameAsync() only stalls in one unit module and not the other, despite being written the exact same way ๐Ÿค”

tender mirage
#

although i'm definitely not so good at it ๐Ÿ˜‚

rich adder
#

the inspector is most efficient way in terms of references.

#

its basically game* compile time dependency injection

tender mirage
#

I know, and i should definitely use anything that makes my life easier

#

also yeah i dont use ++1

#

for consistency, is that weird?

rich adder
#

if you do ++ you don't need 1

tender mirage
#

oh right.

#

it's ++i

#

in this case

rich adder
#

๐Ÿ˜ข

sick arrow
#

can anyone help me with some animation riging?

rich adder
#

but yeah tomato tomato

rich adder
sick arrow
#

thanks i was looking for that channel

tender mirage
#

๐Ÿค

#

oh wait, it is actually i++ isn't it.

#

not ++i

rich adder
#

yes

tender mirage
#

yeah. i don't use ++ at all..

rich adder
#

if you did ++7 that would not make much sense

#

wait it works..

#

huh TIL

hot wadi
#

It's just the order of the calculation

rich adder
#

right..pre-increment vs post

tender mirage
#

huh.

#

dangit. i somehow feel like that could be something neat to use for counting.

#

and i don't even use the normal one.

naive pawn
#

the difference only really matters when you want to use and immediately increment or vice versa

#

typically with implementing lists/stacks with arrays

rich adder
#

ya in for loop they do the same thing I think ?

tender mirage
#

that can be really important tho.

#

i can imagine

rough granite
naive pawn
#

if the value isn't used they're compiled into the same thing even
optimization ftw

grand snow
naive pawn
#

(i++ is actually kinda expensive in comparison, in terms of machine cycles)

rich adder
rough granite
# rough granite Odd...

Reminds me of my java teacher that never used Value += Number; and instead always went Value = Value + Number

tender mirage
#

quick question. how long have you guys been coding?

#

like in general

#

anything counts

rich adder
#

I started whan I learned unity ๐Ÿ˜›

rough granite
tender mirage
#

or you've been commited perhaps. hehe

naive pawn
rich adder
naive pawn
rough granite
naive pawn
rocky rock
#

I started learning to code 15 years ago blobsweat

naive pawn
#

i don't really know the actual languages. i can read but not write, but i can write assembly level logic
ive made 2 cpus and working on a third in turing complete (hard recommend)

rough granite
naive pawn
#

oh and ive read assembly in ctf puzzles (cybersec)

rich adder
zenith cypress
naive pawn
rough granite
hot wadi
naive pawn
#

the differences are optimized out in both languages if the value isn't used

tender mirage
rich adder
tender mirage
naive pawn
#

bro im in first year uni

rich adder
tender mirage
rough granite
tender mirage
#

yeah, sorry for the assumption

tender mirage
#

it's like using blender..

#

but its a game engine

rich adder
#

there is just so much C++ boiler (in Unreal) you have to write for simple systems that Im just like "yeah I can do this in c# in a few minutes..." I'm not enticed to use unreal much if I can do the same things in Unity but quicker

tender mirage
rich adder
#

I enjoy doing unreal for cinematics and video work

tender mirage
#

i' was modding with some unreal uassets, it's very interesting how the reverse engineering works with that engine

rich adder
tender mirage
rich adder
tender mirage
#

even that seems not so fun

#

lol

rich adder
#

creeping into offtopic here ๐Ÿ˜…
but yea it gets messy quick and at times you really do tell yourself "I can do this In code soo much quicker (in Unity) " But if I work with someone else I muster through

rough granite
rich adder
#

In Unity/Unreal seems good when working with designers though, instead of doing like 50 custom tools in code ๐Ÿ˜›

rough granite
zenith cypress
tender mirage
rich adder
rough granite
naive pawn
#

it makes a difference if you actually take the result of the operation

rich adder
zenith cypress
rough granite
naive pawn
rich adder
thorn holly
#

is it bad practice to use the legacy and modern version of the animator at the same time? I usually use the modern one but theres one specific thing here where it would be very helpful to create an animation at runtime, which it seems the modern version cant do

rich adder
#

wdyn "Legacy Animator"
are you confusing it with Animation component ?

tender mirage
#

while you're at it

naive pawn
rough granite
zenith cypress
#

Yeah (in C# at least)

ldloc.0
dup
ldc.i4.1
add
stloc.0

vs

ldloc.0
ldc.i4.1
add
dup
stloc.0

(just throwing out the list for ref)

thorn holly
rough granite
rich adder
thorn holly
#

so is it bad practice to use the animation component while using the mecanim animation system?

rich adder
rough granite
zenith cypress
#

No il colors, so had to use cs colors LMAOO

thorn holly
#

thru scripting

#

hence i asked here instead of unity talk

rich adder
naive pawn
#

source code:

void w() {
    int a = 0;
    a++;
}
void x() {
    int a = 0;
    ++a;
}
void y() {
    int a = 0;
    int b = ++a;
}
void z() {
    int a = 0;
    int b = a++;
}
```C# compilation (IL)
w: `ldloc.0`, `ldc.i4.1`, `add`, `stloc.0`
x: `ldloc.0`, `ldc.i4.1`, `add`, `stloc.0`
y: `ldloc.0`, `ldc.i4.1`, `add`, `dup`, `stloc.0`, `stloc.1`
z: `ldloc.0`, `dup`, `ldc.i4.1`, `add`, `stloc.0`, `stloc.1`
C++ compilation (asm)
w: `add DWORD PTR [rbp-4], 1`
x: `add DWORD PTR [rbp-4], 1`
y: `add DWORD PTR [rbp-4], 1`, `mov eax, DWORD PTR [rbp-4]`, `mov DWORD PTR [rbp-8], eax`
z: `mov eax, DWORD PTR [rbp-4]`, `lea edx, [rax+1]`, `mov DWORD PTR [rbp-4], edx`, `mov DWORD PTR [rbp-8], eax`
rich adder
#

at the cost of your particles cannot interact with physics objects like PS can

rich adder
rough granite
naive pawn
rough granite
rich adder
naive pawn
#

also, speed was not the goal in any way

#

this was a comparison of the work done

thorn holly
#

i think thatll work

#

thanks

rough granite
naive pawn
#

the overhead is tiny

#

whatever's in the loop far outshadows the increment

rough granite
haughty forge
#

I'm so bad at Unity, how to code?

rough granite
haughty forge
#

Sigh

haughty forge
rough granite
rich adder
zenith cypress
#

Gotta get through the boring to get to the good stuff

haughty forge
#

I was just having dream about making my racing game

rough granite
rich adder
haughty forge
#

Fine

rich adder
haughty forge
#

First of all, i'm trying to avoid copyrighted codes

#

And idk what to do

rich adder
#

copyrighted codes?

rich adder
haughty forge
#

Yes, the scripts is also copyrighted

rich adder
edgy sinew
#

CodeMonkey doesnt give a sh** at all, bad resource 100%

#

90% of Unity videos are doing WrongLerp so ...

rich adder
#

yet he's popular ๐Ÿคทโ€โ™‚๏ธ so must be doing something right

rough granite
edgy sinew
#

Because of the results people think, wow that looks pretty good!

rich adder
#

who knows.. I just know that unity using his shit on their site is ultimate cringe

edgy sinew
zenith cypress
edgy sinew
#

Same reason AI generated code gets approved in PRs

naive pawn
# rough granite Fair was just curious if there would be any effect in a huge loop

let's say you have a loop adding 2 10-element arrays of vector3's memberwise
3 instr are for the for initialization
6 instr per loop plus the end, so 65 instr are for the inc and cond
so overall 68 instr of overhead on the for

meanwhile the actual work, 10+28 per loop, so 380 instr for the work

would be more with a list, since there's also the overhead with calling each method too

rich adder
#

I mean on one of this video he really claim doing transform.Find("TheThing") was "good code" lol

rough granite
naive pawn
#

and this is a very simple loop with minimal work too

grand snow
#

I feel like worrying about i++ or ++i is silly as we can probably trust the compiler to optimise this based on usage

rich adder
#

I opened a whole can of worms ๐Ÿฅน

grave bluff
#

idk what to believe anymore

zenith cypress
#

they also insist you use C++, so can you really trust them heh

rich adder
#

wait..isn't C++ just D ๐Ÿค”

grave bluff
rich adder
grand snow
#

godbolt can show you anyway what it will do

edgy sinew
#

โญ hi guys, is it computationally expensive to be passing around parameters like this all the time? This is a static Spring class based on Ryan Juckett's work.

I'm considering to make it non-static and just have an instance wherever I need a Spring. So the values are just there in the instance, not always being passed into functions.

        ref tDampedSpringMotionParams   pOutParams,       // motion parameters result
        float                            deltaTime,        // time step to advance
        float                            angularFrequency, // angular frequency of motion
        float                            dampingRatio,
        ref float                           pPos,           // position value to update
        ref float                           pVel,           // velocity value to update
        float                               equilibriumPos, // position to approach
        in tDampedSpringMotionParams        springParams)```
grand snow
#

most here is stack allocated so no

#

best place for variables to be!

rich adder
#

value types woo

edgy sinew
#

I see. You really think I wouldn't gain any performance by having instances with member variables instead?

#

It seems so strange to be passing around 8 variables all the time.

grand snow
#

when all the needed variables are all together (such as in the stack) then thats the best case

#

(we know here most of these arguments will be because they are value types)

#

the ref float args im not sure, depends on where they are from

edgy sinew
#

I have 1 more question.
If I have some function, is it worthwhile to check if it needs to be called before calling it? Or is it equivalent to check within the function itself and exit if no action needed?

grand snow
#

Lots of args and called a lot? better to avoid the call early

edgy sinew
#

So for example with the code I sent.

#
// Option 1 check before call function
if (currentPosition != desiredPosition)
    UpdateSpringStuff( parameters)

// Option 2 check inside of function
UpdateSpringStuff( parameters) {
    if(currentPosition == desiredPosition)
        return;
    ...
}
#

Option 1 is better because we avoid having to pass in those 8 arguments right? And the function call overall

#

Kinda feels like I just answered my own question ๐Ÿค”

#

In-function "check if any action needed" is so much cleaner and self-contained but. Yeah passing parameters around for nothing just sounds wasteful

#

I suppose with an instanced class it's possible to avoid the function call and self-contain the check. Idk. That's why I didn't want to use a static class

#

For something that will be around for the entire game/scene, why would I keep it static? Rather keep all the stuff together in an instance of the utility.

polar dust
#

Generally you should return inside a method when it's unable to continue what it's doing. Maybe it creates list, checks the list, and returns early if that list had more than 5 items.
Only that method had any knowledge of the list inside of it, only the method can return.

As for checking before calling it, simplest would be if it's a method to capitalise a string. If the string is empty, you know there's no point calling the method in the first place

naive pawn
naive pawn
#

well.. reference types would also be copied around

edgy sinew
#

I thought ref just passes a reference (location in memory)

naive pawn
#

the ref... i guess that would also be "copied"?

naive pawn
edgy sinew
#

Objects are always passed by ref, too, I think

#

Value types are copied, i think there's exceptions with that too

naive pawn
#

a ref is just a 64 bit integer that represents an address
a float is just a 32 bit integer that represents a real number

#

both cases they'd be copied

#

wouldn't the "bad" case be with copying a large value type?

edgy sinew
naive pawn
#

though, it's still a limited amount of copies, so probably not an issue either

edgy sinew
#

Well I suppose pass by value can be faster than.

#

But it creates a copy of it, so ... Idk

naive pawn
#

probably not

#

to my understanding, passing arguments inherently does copying
how much is copied depends on the types

edgy sinew
naive pawn
#

i will have to stop myself there because i am now realizing that this is most definitely micro-optimization and absolutely does not matter

#

design it in a way that makes sense and is easy to use, don't worry about the perf

edgy sinew
#

I can't keep losing FPS so I need to know these details

#

Thanks guys for the knowledge

naive pawn
#

it's not because of your arguments, it's more likely due to the actual work being done

#

to put this into perspective:
the thing you're worrying about, is going to be like 0.5% of the work your cpu does.
optimizing it won't get you anywhere

polar dust
#

You can worry about it when that 300fps turns into 3fps

edgy sinew
polar dust
#

well, "when" is a little mean ๐Ÿ˜†

edgy sinew
#

on my cheaper machine, I'm only at 180 FPS. Used to be 280

#

The triple raycasts probably contribute

#

But this spring related stuff dropped it further

naive pawn
grand snow
naive pawn
#

otherwise you end up spending 50 minutes for an extra +0.05 fps for something that was already very optimized

edgy sinew
#

I don't need the profiler, I'm looking to write tight and minimalist code.

naive pawn
#

you most definitely need the profiler if you want to actually make meaningful optimizations

edgy sinew
#

I'll let you know if I need it

#

For now I've just been cleaning my code and gaining FPS

#

Except for this Spring crap, passing 8 params around every frame. Nuts

naive pawn
#

yeah the 8 params are not the cause, man

edgy sinew
polar dust
#

Performance of a build is different to performance while in the editor. If it's running well in the editor, just assume it'll run fine in a build.

When the time comes to actually making the build perform well, that's ultimately a future you problem which doesn't exist atm

naive pawn
polar dust
#

Debug.Log impacts performance, too many of those can tank the framerate (don't not use it because of that)

naive pawn
#

if you don't have any more obvious stuff (no, 8 params is not "obvious unoptimized code") then you will need to use the profiler to see what's actually going on instead of guessing

edgy sinew
#

Bold accusation bro

#

The Spring code, yes. It's from Ryan Juckett i said that

naive pawn
#

that's literally what you said you did

#

i'm referring to this part

For now I've just been cleaning my code and gaining FPS

edgy sinew
#

My bad. I thought you meant my entire code

naive pawn
#

i'm saying you found patches of unoptimized code within your codebase and fixed them

edgy sinew
#

Ohh gosh my bad dude. I'm feeling attacked rn taht's all

edgy sinew
# edgy sinew Will try now

... They are though ... Just checked before-function-call and the framerate doesn't dip to 240 anymore

naive pawn
#

checked... what exactly?

thorn holly
#

Donโ€™t worry about ur fps too much lol itโ€™s going to naturally decline as you make stuff

#

I put in a tile system and my game dropped from 900 to 200

#

lol

naive pawn
#

it's the functions themselves

edgy sinew
#

yes

naive pawn
#

not passing the params

edgy sinew
#

I see. Okay

naive pawn
#
void X() {
  for (int i = 0; i < 1000000; i++) {}
}

void A() {
  if (Random.value < 0.5) X();
}

void B() {
  X();
  if (Random.value < 0.5) return;
}
edgy sinew
#

Got a lot of if (function call required) call function() to do ๐Ÿฅฒ

naive pawn
rich adder
edgy sinew
naive pawn
#

they can clean up a lot of logic if used properly

edgy sinew
#

I never call a function with params, I just use instance variables always

#

What?

#

You mean checking in-function?

thorn holly
naive pawn
#
// normal conditional
if (x) DoY();

// guard clause
if (!x) return;
DoY();
naive pawn
#

helps if x is an exception rather than a requirement, it makes it easier to read

naive pawn
#

x is checked before calling DoY there in both cases

#

it's just a styling thing that can make it easier to read when applied correctly

edgy sinew
#

Ah ok, that's what they call it huh.

glass summit
#

could someone explain why is this an error?

edgy sinew
#

In an Update loop with many function calls, can't just return so.

#

Maybe if they were all separate but anyway.

rich adder
rich adder
edgy sinew
thorn holly
#

Oh you mean unitys built in one?

rich adder
#

yea

thorn holly
#

I used unitys yeah

rich adder
#

ohhh ok

glass summit
glass summit
edgy sinew
#
if(canFire) == true)```
#

2nd one is no good eh? Unnecessary ) close

rich adder
# glass summit

because you closed statement early for it == true doesnt make sense

naive pawn
#

not quite

rich adder
#

btw you can omit == true anyway..

#

if(canFire) works exactly the same

thorn holly
rich adder
#

i thinks you wanted to do if(canFire) { //stuff so adding == true after a closed statement confused it ๐Ÿ˜›

edgy sinew
#

instanced class that has all the data available at any time > passing data around to static functions every frame ๐Ÿคทโ€โ™‚๏ธ

thorn holly
hot wadi
#

I guess itโ€™s way more obvious that way in the beginning. U get to know better the longer u code

#

My teacher technically said โ€œmake me a game in C++โ€ for the mid-term

still ingot
#

I keep on getting an error when I try to add my array to my custom editor?

            if (dialogueSettingGroup)
            {
                EditorGUILayout.PropertyField(dialogueText);
                EditorGUILayout.PropertyField(dialogueArray);
            }
            EditorGUILayout.EndFoldoutHeaderGroup();```
rich adder
grand snow
#

I basically never see explicit boolean comparisons apart from beginner code

#

once you understand that the bool itself is sufficient then you can stop

odd radish
#

Hey guys, I'm trying to make a procedural generated hospital with basic modular assets, a plain wall, wall with door and wall with window (1m x 3m). I also have a floor that works as a ceiling at the same time (1m x 1m). I want to create a script that will procedurally generate a building out of these assets with following room groups:
Corridor (A main corridor connecting one or two other corridors for example 12m long, that also can attach the two other groups of rooms)
A "patient" room (2 types: 8m x 4m and 3m x 4m)
A "examination" room (4m x 4m, spawns less then the patient room)
All these rooms need to contain different assets, but that will be added later.

Anyone knows where I can find a good tutorial about this or paper to read on? Or anyone who can help me on my way on how I should start with this?

rich adder
#

break down your issue into a more generic thing you will find it easier

#

there are a couple of procedural algorithms you can use BFS etc.

#

the rooms themselves are easy to randomize tho, you can have different prefabs that spawn in random, the room with different layouts

#

maybe even easier to use "snap points" at the door of each part then use some pathing algo to connect them doing some physics overlaps (a bit more brute force but works)

dark laurel
#

I can't recall why this is, but I have a canvas and canvas scaler, and whenever I recompile it defaults to portrait - if I change tabs to game mode then back, it resizes properly. What the heck am I forgetting?

edgy sinew
#

I did gain the convenience of all my data being within the class instance though. So I can add a new Spring with only 5 lines of code rather than 10+ and no if statements (the instance checks before it does any work.)

grand snow
#

Probably why it fixed itself when you went to the game window

dark laurel
#

I've fixed this in projects in the past though.. but forgot how. It's kinda driving me batty

#

It's such a minor annoyance :p

hallow acorn
#

can triple nested for loops themselves cause performance issues? its probably mostly their content right?

dark laurel
#

yes, depends on how often you call them and how many elements they have

rich adder
#

triple nested loops are very important at times

dark laurel
#
for (int i = 0; i < 1; i++) for (int j = 0; j < 1; j++) for (int k = 0; k < 1; k++) // 1 operation
for (int i = 0; i < 1000; i++) for (int j = 0; j < 1000; j++) for (int k = 0; k < 1000; k++) // 1b operations
rich adder
#

especially working with multidemensional arrays

hallow acorn
hallow acorn
edgy sinew
dark laurel
#

depends on what you're doing in the bottom, if it's just math then it's probably pretty fast

rich adder
edgy sinew
#

I read somewhere to avoid code branching - and try to use Math as much as possible.

dark laurel
#

32k operations per frame is trivial for x ++ and game killing if it's something else

edgy sinew
#

Like Lerp between 2 different "modes" of camera follow for example, rather than if (camFollowMode == ...)

#

I'm not sure which is more expensive.

rich adder
#

cinemachine ๐Ÿ˜ฟ

edgy sinew
#

Love Cinemachine. I only use Hard Look At Target though.

#

Don't like their 3 ring orbit crap. Deoccluder is great

rich adder
#

ohh you're missing some really cool shit, cinemachine can do wayyy more

edgy sinew
#

๐Ÿคทโ€โ™‚๏ธ

dark laurel
#

again, it's a matter of scale.. if eat a grain of rice 32k times per day, you'll live.. if you eat a chicken nugget.....

edgy sinew
hallow acorn
#

ive noticed that updating every chunk of my terrain algorithm once per second increases my frame time from 3 to 700ms which isnt good im pretty sure. im looking through my code rn and looking at every line and trying to find my massive performance loss. probably the best way would be to rewrite my algorithm as a compute shader

edgy sinew
#

Can't say I have any complaints. Unity's built in stuff is just ... Code anyway, so

#

Excluding complex stuff that uses Jobs like IK, I found writing my own implementations is just better

#

"better" in a "i can get the exact result i want" way

rich adder
#

yeah if its tailored to your need ofc.. I just trust engineers that know way more than me making all the solid implementations , Cinemachine is one of them

#

the damping alone takes away so much bs with doing custom Tween

#

dont even get me started on Blends without cinemachine

edgy sinew
#

I use my own camera smooth following code

#

Vector3.SmoothDamp didn't give me the customization that using Curves did, so. I even avoided that

rich adder
#

You gotta tune a bit but eventually you get really nice cameras, depends on your needs. I mostly use it for cinematics and their awesome spline / tracking

#

oh and the camera shakes makes things really nice.. Recoil, Hand-Held feel all that crap you have spend time making Algortihms for noise.. in CM is just 1 component , dont even get me started on the Obstacle Avoidance (basically its just a bunch of physics queries xD)

edgy sinew
#

I've seen so many bad tutorials on IK (procedural) recoil.

hallow acorn
#

should i set my terrain chunk to static if its mesh can change/update?

rich adder
edgy sinew
rich adder
#

if you want specific/predictable patterns per weapon, ala Counter-Strike and such.. Check out TheKiwiCoder he has some on that (maybe there are newer ones but he had them when i was looking into it years ago)

#

This video uses the Unity Animation Rigging Override Transform Constraint and CinemachineImpulseSource component to achieve a weapon recoil effect. The Impulse source listener is used to add camera shake effects, while the Override Transform constraint is used to animate the character and the weapon.

โ–บ Previous Video: https://youtu.be/HZuaz...

โ–ถ Play video
edgy sinew
#

But the camera shake is from Cinemachine

rich adder
#

yeah it just basically moves the transform for you

#

so you can basically make your own patterns with ease

hallow acorn
#

can someone help me optimize my code? i get like a solid .4 fps

#

i dont think thats really great

edgy sinew
rich adder
rich adder
#

thats the first step

#

it will tell you everything about whats happening

hallow acorn
#

but its def. the code thats for sure

edgy sinew
#

.4fps is wild bro, let's start with what u got going on

#

500 Rigidbodies colliding?

hallow acorn
rich adder
edgy sinew
#

how much code is there total happening at runtime?

hallow acorn
#

but my terrain is really expensive i fear

edgy sinew
#

So if you remove terrain and run around on a flat Plane, what's the FPS?

rich adder
#

you'd be surprised some times, for me it was always some URP thing or PostProcessing in the graphics

#

my code was doing 1kb at most

hallow acorn
edgy sinew
hallow acorn
#

yes

#

i already split it up in smaller chunks tho

#

dont want to get .1fps haha...

#

i feel like marching cubes is quite expensive

edgy sinew
#

Well. That's a lot of code.

hallow acorn
#

SetHeights() shouldnt be a problem. SetMesh() and MarchCubes() might be the cause tough

hallow acorn
rich adder
#

and "Deep Profile" to see code

#

though its recommended you do these in a build because in editor there is still some overhead to keep in mind

hallow acorn
rich adder
hallow acorn
shell sorrel
#

look at your gc allocations as well in the heirarchy

hallow acorn
#

bro these are a lot of kb i dont like this

#

unity uses 97%of my 32gb ram btw

#

wait

#

thats 35gb

shell sorrel
#

you using deep profiling?

#

if so yeah it needs a crap ton of ram

#

best to figure out what you need to deep profile first and run it as little as possible to get the info you need

hallow acorn
#

my spotify crashed because of it

rich adder
#

did you put an infinite loop lol

shell sorrel
#

even know i mostly develop from my laptop, i will often deep profile builds from my desktop since the laptop only has 48gb ram

rich adder
#

how you eating so much ram

hallow acorn
shell sorrel
rich adder
#

sounds like it lol I run like 7 instances of unity and one uses 5 max

shell sorrel
#

its usage gets high quick

rich adder
#

oh yeah possibly the profiler

#

but code that probably creating trash sounds likely too

hallow acorn
#

my editor is still frozen its been 10 minutes now

shell sorrel
#

i would not use deep profiling till you narrow down where it should be used

#

also would profile builds not editor

hallow acorn
rich adder
#

though for me deep profiling was useful narrow specific function

shell sorrel
#

the spikes in your graph above look like garbage collection to me, so good chance you are making alot of allocations per frame

rich adder
#

I hate that they made Rendering and Garbage so close in color...

#

I always mistake them

shell sorrel
rich adder
#

bruh couldnt picked a purple or some shit

shell sorrel
#

but its easy to confirm in the hieharhcy view

rich adder
#

true

shell sorrel
#

if you sort by gc allocs

#

but also consistient spikes like that often just mean you are allocating too much a frame

hallow acorn
rich adder
#

yeah the frequent cleanup will def slow your shit up

hallow acorn
shell sorrel
#

there is almost always a way to not allocate per frame

hallow acorn
#

should i just terminate unity and restart it? code is saved and didnt make to many changes. its been frozen for 17 minutes now

rich adder
#

probably a good idea to conclude you made sludge and should end it

shell sorrel
#

i would

rich adder
#

corporate hate this one simple trick

shell sorrel
#

if you need to force quite and things are unstable afterwards. just close unity and delete your projects library folder and let it reimport it all

rich adder
#

refresh that cache baby!

#

you probably got like 20gb in there ๐Ÿ˜†

hallow acorn
#

what should i delete??

rich adder
#

the Library folder

#

MyProject/Library/

hallow acorn
shell sorrel
#

while unity is closed

hallow acorn
#

its not even that bad just 1.7gb

rich adder
#

it could still be full of bad cache

tidal lily
#

Hello there,
I have a "vehicle type 1", I want to be able to switch to "vehicle type 2" mid game.
what do you suggest the best way to do that?
Like I have other scripts like camera follow script that requires the transform component of the player vehicle.
and vehicle type 1 type 2 are different from eachother so I prefer not to combine them into a single gameobject.

I tried making a vehicle manger gameobject that can switch, it worked but the issue is the current vehicle transform data when I try to access it from the scripts like the camera for example.

rich adder
#

if its gone Unity regenerates this when you open a project

hallow acorn
#

cant delete it it says files in there are open but i have unity and even vs code closed

rich adder
rich adder
edgy sinew
tidal lily
hallow acorn
edgy sinew
#

Or fully switch to a different object - different location on the map etc

edgy sinew
rich adder