#archived-code-general

1 messages ยท Page 400 of 1

rain minnow
#

it'll work using physics or by manipulating the transform . . .

#

you just need to use the local time scale correctly (depending on how you move the rigidbody) . . .

#

@peak gull first, you need a custom component that stores the local time scale of the GameObject. this is used to scale the speed of the GameObject to give it the slow-motion effect . . .

#

let me know where you need help at . . .

peak gull
#

im not sure where to apply the time scale

#

im not really sure im applying it properly...

limpid lance
#

I just learned you can inline define variables in c#...
bool addBrackets = valueObj is IDictionary<string, object> d && d.ContainsKey("type") && d["type"] is Type t && t == Type.Function;

rain minnow
peak gull
#

unfortunently i scrapped it and was going to work on exclusively complete time stop

limpid lance
#

for sure angerjoy

peak gull
#

but previouisly i made it so on toggle, it would reduce the objects current velocity and gravity scaling by the time, which did work, but on returning to regular speed is where i had trouble, as its velocity would be higher than origin.

#

it works if there is no gravity but...

peak gull
rain minnow
peak gull
#

its just the issue of applying it, then reverting it back to normal speed

#

i have a manager that detects if the game should be in the state of "normal" or changed time

#

all objects that should be affected are added to a list on awake

rain minnow
peak gull
#

when called, each object in the list will have the slowed effect, and the reverse will happen if called to revert to standard time

#

for example if the speed is 0.5

#

all objects will see that value and decrease their current velocity and gravity by 50%

#

and on returning to normal, increase back by doubling it in this case

rain minnow
#

you can do that two ways:

  • store current value, reset back to current value
  • modify current value by effect amount by adding or subtracting, then do the opposite . . .
peak gull
#

the only problem i have currently is gravity

#

as gravity constantly changes the velocity

#

so the doubling of the velocity causes some weird things to happen when gravity does its thing

#

i tested it without gravity and it works as intended

#

but with gravity, it would slow down, or speed up on returning to normal time

rain minnow
#

it'd be easier to affect them using the time scale instead of altering the speed and the gravity . . .

peak gull
#

but how do i apply individual time scales

rain minnow
#

but i would revert the gravity first, then the velocity. have you tried that?

peak gull
#

because from what i researched time scale is global and there is no local time scale

rain minnow
peak gull
#

ok let me

#

back track my code lol

rain minnow
peak gull
#

how do i make a local time scale...

#

the transition from normal time to slowed time works

rain minnow
# peak gull how do i make a local time scale...

here's an example of mine. i have my component to track the GameObject's local time scale. the MoveTimeObject component moves the GameObject based on the value of it. currently, it moves at 1/3 the normal speed . . .

peak gull
#

the timemanager determines what the strength of the slowdown effect

#

and player characters are excluded

rain minnow
#

a quick fix is to store the velocity in a private variable before multiplying by your global time scale, then assigning the velocity to its (previously) stored value upon deactivation . . .

peak gull
#

the problem is that if that object collides with an object, its stored velocity will be different

#

that only applies to complete time stop which i was going to do since i couldnt figure out how to calculate all that physics

#

and i cant find anything on changing timescale on specific objects

#

as it just applies it globaly

#

unless i missed a setting somewhere

rain minnow
#

i have _timeScale; that is local to the GameObject. then i have properties for DeltaTime, FixedDeltaTime, and TimeScale. these properties are used to move the GameObject based on rigidbody movement or manipulating the transform . . .

#

all i have to do is use those properties when i move the GameObject and it will move according to its local time scale . . .

peak gull
#

but how do i apply deltatime to physics

rain minnow
#

you have to use it correctly based on the type of rigidbody movement . . .

peak gull
#

i can program my own gravity and movement, but objects hitting each other is a bit iffy

#

i think ill just settle with complete time stop

#

much simpler to program

rain minnow
dawn nebula
#

So I want to know if what I'm doing is alright. I want to make a Timeline track that allows me to animate gameobjects moving along a spline. For the track binding type, it's a transform, and I have an exposed reference to the Spline container that contains the spline to move along.

#

Is this... alright? Never messed with exposed reference.

rain minnow
#

it demonstrates how to use the correct time method based on the type of rigidbody movement . . .

peak gull
#

thanks for trying to help me tho

rain minnow
#

sure, it's just a demo on how to move the objects with an independent time scale. you only have to worry about assigning velocity, calling AddForce, or MovePosition for the GameObject. any script can access the TimeObject class to change the local time scale for that GameObject to give it an effect . . .

#

i just tested collision using velocity; they still maintain their current speed with their local time scale . . .

kind willow
#

So apparently, when you are force playing another animation, the previous one playing sending out all animation events
I don't want that, any workaround known?
Except for making a special bool check on event callback

hexed pecan
kind willow
#

I don't get it

hexed pecan
#

From AnimationEvent you can get its .state and there you can get the .weight

kind willow
#

how can I use an AnimationEvent as a parameter if it's a callback

hexed pecan
#

Something like```cs

public void MyAnimMethod(AnimationEvent evt)
{
if (evt.animatorClipInfo.weight < 0.5f)
return;
```

hexed pecan
#

IIRC you can keep the event in the animation as it is

kind willow
#

okay I got the concept

#

but I don't think that I could get any useful information out of the weight

hexed pecan
#

Theres probably a way to check if its state is the current playing state or not

kind willow
#
  • animation with an event plays
  • I force playing totally different animation through code
  • even fires
hexed pecan
#

You want to ignore those?

kind willow
#

yeah I want to skip the animation and discard all events caused by that

hexed pecan
#

Well thats what i was explaining

kind willow
#

oh well

#

I just realized that I am starting to play the same animation

#

not the another one

#

and I still want to discard the event

#

gonna try the timecheck

onyx cypress
#

im trying to make a script where you have to collect fuel to power the generator. the generator works the first time i collect the fuel but the second time i click on the fuel the bar doesnt apear or the fuel counter doesnt increase
https://hastebin.skyra.pw/kujopabidu.csharp

kind willow
#

that's not related to the question but

#

genOnScript.GenBattery.fillAmount -= 0.0001f;

#

what you do there?

#

you should multiply that by Time.deltaTime probably if you want that being not frame dependent

onyx cypress
vestal arch
kind willow
winged jacinth
#

A query, if i want to change a property of a component through script for all the gameobjects that are in the scene and have that component what should i do,
for example i have several water bodies in my project at different place and i need change their buoyancy when a certain button is clicked,
do i have to search and store them in a list or array with tag and then loop all through to change it or is there anything better

knotty sun
winged jacinth
#

yeah it has to be bcz i can switch waterbodies at same time

#

actually i am switching between floating and diving so i hope u got the point

knotty sun
#

so make the backing field for the property static, that was you can change them all in one statement

winged jacinth
#

backing field ?

knotty sun
#

you do know properties have backing fiellds, right?

winged jacinth
#

nope sorry

kind willow
#

is buoyancy even in a custom script or a component field?

#

got a question how to change component's field

winged jacinth
#

component field and to be changed thru script

#

get that component in ur script and u can change any field in it

knotty sun
# winged jacinth nope sorry

ok

int myprop { get; set }

this is a property with an automatic backing field

int myint;
int myprop { get { return myint;} set { myint = value; } }

this is a property with a manual backing field

kind willow
#

I mean if it was a custom script I would slap a ScripableObject or as you said a static propery field, that sounds nice

#

but if it's a unity component, well

#

no idea how to make it so that component use my custom property as it's value

winged jacinth
#

steven can i send a ss of the script

knotty sun
#

sure

winged jacinth
knotty sun
#

ok, so none of those are properties

winged jacinth
#

ohh i see

knotty sun
#

they are just fields. so make the buoyancy field static

winged jacinth
#

to be correct, when i am declaring buoyancy class variable that has to be static

#

like this

knotty sun
kind willow
#

I ain't getting it
can a component be static?

winged jacinth
#

kk let me try, Thanks

knotty sun
kind willow
#

that sounds like you can assign one component to multiple gameobjects and I don't comprehand

#

can you do that?

knotty sun
#

no, but this is a user class, no

kind willow
#

buoyancy effector 2d is a user one?

winged jacinth
#

it didnt work though
and no it is a unity component

vestal arch
#

well you'll need some way to initially set it

knotty sun
#

best thing i can think to do is add the Buoyancy component to an empty game object and in your script treat the reference like it was a singleton

kind willow
#

but you have to have a buoyancy script on each body of water don't you

winged jacinth
#

i did tried that but as you know buoyancy effector needs rigidbodies

knotty sun
#

Ah, so you cannot have just one shared Buoyancy class

kind willow
#

that's a regular unity component it seems

winged jacinth
#

yup

knotty sun
#

Yeah but I have no idea what it does or how it works, it's a new one to me\

vestal arch
#

it's just density that you have to set, right?

winged jacinth
#

yup

#

for all the gameobjects

vestal arch
#

just make another component, singleton if you want, that holds the density

#

then for each body of water that you want to change, have it reference that component/access the singleton to query for changes

#

just a guess: you might want to query it for changes, and only if it's changed, set the new density? in case there's extra costs with setting the density

winged jacinth
#

so like there are these 3 so i create a new script and then change density in and then call that function to where i change

kind willow
#

that's the question if you can do something better than having a list of references to go through each time value changes

knotty sun
#

Another option would be to use an event which fires when the density is changed

winged jacinth
#

but will it change on all the gameobjects

knotty sun
#

if the objects subscribe to the event, yes

kind willow
#

wait can they not?

knotty sun
winged jacinth
#

how they will as they are a prefab.

#

should i just attach a script that subscribes to the event

vestal arch
#

yes

winged jacinth
#

to the prefab

vestal arch
#

if you're going for events, yes

kind willow
#

subscribe on awake unsubscribe in destroy I guess

winged jacinth
#

kk i will try and check then,
just to be confirm again the event will be in the class where i am triggering right ?

#

where i am switching the mode

kind willow
#

so it's really the same

winged jacinth
#

this is a singleton right ?

kind willow
#

kinda

knotty sun
kind willow
#

ok I broke my brain

vestal arch
# kind willow ok I broke my brain

the difference is which is responsible for the change
with a list, the thing holding the list is responsible
with an event, the thing subscribing is responsible; it's just told that something happened, it has to do the change itself

knotty sun
winged jacinth
#

initialization mean on awake right, instance = this;

knotty sun
#

yes

winged jacinth
#

yup i did it ๐Ÿ™‚

#

ok guys i found another solution wanna listen if i am not bothering ๐Ÿ˜…

#

as in reality water never changes its buoyancy what effects sinking or floating is the mass of the object so instead of changing buoyance i changed the mass and a little bit gravity on the player so it will act same on all water bodies.

kind willow
#

makes sense, that's how submarines work

#

aside for a gravity part...

knotty sun
wheat spruce
#

I keep forgetting how good extension methods are

zenith acorn
#

I'm doing Ui with vertical layout group and for some reason when I add items the spacing is so huge but I checked the padding and spacing of the items and it is all 0

wheat spruce
#

Ive got some classes that store Vector2, but I need to get them as Vector3 (just without a y value), and it was getting really annoying having to write
new Vector3(myvec.x, 0f, myvec.y); over and over again

zenith acorn
#

Also for some reason the words are placed in the middle even though the child alignment mode that I have chosen is middle left

wheat spruce
#

The trick is to use this

  public static Vector3 ConvertToVec3(this Vector2 vec, float yValue = 0f)
  {
    return new Vector3(vec.x, yValue, vec.y);
  }```
steady moat
wheat spruce
#

you can then write myvec2.ConvertToVec3() and thats all there is too it

steady moat
wheat spruce
#

what I'm not sure if is what is this kind of thing called? like the term that describes how that kind of extension works

steady moat
wheat spruce
#

I know its an extension method, I just mean the overall concept of what they are

#

like how OOP has encapsulation and polymorphism

wheat spruce
#

aah

#

does C# have any other things like this? I know a number of little tricks that let you write simpler and less obtuse code

dusk apex
#

!cs

tawny elkBOT
leaden ice
#

C# has hundreds of features.

wheat spruce
#

yeah, a lot of the ones Ive found were more or less stumbled across

#

for instance saw somebody use a lambda like float Diameter => Radius * 2f;

dusk apex
wheat spruce
leaden ice
wheat spruce
#

I've always found the C# documentation to be a bit tough to understand. Like in the expression bodied member page, I understand the way its explaining things but a lot of that is because I know what this is

#

though I suppose it being tough to understand means its good, because they arent dumbing everything down

languid hound
#

There's a lot of terms I tend to forget

#

I found they never really mattered to me in any projects as long as i knew what i was doing so they just slipped

wheat spruce
#

yeah, i've overwhelmed myself in the past when I tried to do a big "lets learn as many new things as possible", the information never sticks

knotty sun
languid hound
#

For me it never was

#

But I suppose it would matter more in actually big teams

knotty sun
#

so you would prefer people to say 'a void thingy' rather than 'method' ?

languid hound
#

Well no maybe I just explained badly

#

I know all the terms I need to

wheat spruce
#

I find its easy to try and find new features when theres a very clear "this doesnt seem like a good way to write that". Like in the early days I'd look at a wall of if else blocks and that made me question that approach

languid hound
#

But expression bodied member is not one I would know off the top of my head

#

Despite the fact I know how to use one

wheat spruce
#

over time ive picked up a lot of tricks like that, issue is its usually really obvious things that stand out

#

its all those things I've never noticed that elude me

#

I'd have never realised you could do this

#

Vector2 Center => new Vector2(x, y); wouldnt have stood out to me

#

it was only coming across somebodies code where they wrote new(x, y) that caught my eye

heady iris
#

knowing what things are called makes it significantly easier to communicate

wheat spruce
#

oh yeah, 100%

heady iris
#

I TA'd a class for college freshmen that used C++. I found it very useful to be able to exactly name every concept I was describing

#

(i wound up reading a good chunk of the standard)

wheat spruce
#

I tried learning zbrush years ago, and the hardest part was that I had no idea what youd call certain things. Moment something went wrong, or I couldnt make it do something, it makes it hard to look for help when the question turns into "this something isnt doing whatever some action is"

heady iris
#

the florpicator

wheat spruce
#

I find chatgpt can be helpful to explain certain concepts or features, especially as the wording of the question can be extremely vague and badly worded, which generally it will be when I only have a vague idea of what I want to know

#

I dislike using it like that, Google has always been my go to for most things, but past couple of years its search results have started to become useless

#

I tried looking for information on subdividing geometry and increasing the density of vertices in a mesh, and 5 of the top results were posts asking about poly reduction and doing a low-poly effect

kind willow
#

I tend to use - at searches if that happen

#

not always helps tho

#
  • should be filtering out specific words
#

"-"

rain minnow
#

But Zbrush has documentation for the editor. You should be able to search/scroll until you get to the section where you use(d) the thing . . .

wheat spruce
heady iris
#

the secret is site:reddit.com

wheat spruce
#

honestly yeah

#

appending reddit to the end is the only way to get reliable results

kind willow
#

I ve heard that as a meme

#

but come one is it really that

#

that bad

wheat spruce
#

I cant be the first one to notice it, but it feels like they've made the search algorithm prioritise providing the most amount of answers to a search, even if it means totally ignoring what you requested (and without it doing the "showing results for" thing)

#

in the past you could search for pretty niche and strange requests and it would return maybe 8 results. Very good when theres a very specific issue, which there usually is when writing stuff

#

but if it detects the result count wont be as high, it sometimes seems to go "the user probably meant to use this other word, that gives millions of results, so thats what I'll return"

heady iris
#

otherwise you just get a tidal wave of content farms

wheat spruce
#

like when I looked for stuff on increasing polygons for a mesh, maybe it detected there are less results than (the definitley more popular question) of making a model have less polygons, especially for gamedev where people like a lowpoly style

#

I keep meaning to write searches that do this down, I always forget in the moment

#

"worlds widest escalator" is one

#

it insists on swapping "widest" with "longest"

kind willow
#

well that's cursed

#

typing "widest" seems to help greatly

wheat spruce
#

yeah, the number of possible relavent results goes up. And the number of results overall goes down

#

makes sense that if it figures I searched with one word with poor results, but a synonym for "wide" gives better results, it figures thats what Id mean. And its honestly good for most searches as it probably does that a lot where it interprets my search to have meant something else

kind willow
#

have you tried yk now google?

wheat spruce
#

but if it can make such a bold assumption, providing totally wrong results to what I want. Its no wonder why it struggles to help me find answers to some programming questions

hushed coyote
#

Hi, I'm trying to do an OnGround() method for my player but whenever I try to use it on a terrain collider to determine that the player is over it I get a true just at some point but not all the time, this is my function and a video showing the issue (I only move the player if the method returns true)```c#
private bool onGround()
{
return Physics.Raycast(transform.position, Vector3.down, out hit, 1.85F) || rb.linearVelocity.y == 0;
}

fathom rose
hushed coyote
fathom rose
#

I suggest drawing the line to see whats going on. If you're raycasting from the rigidbody itself, the ray should be a little more than half the size.

hushed coyote
#

like this, right? c# void OnDrawGizmos() { Gizmos.DrawRay(new Ray(new Vector3(transform.position.x, transform.position.y, transform.position.z), Vector3.down * hit.distance)); }

fathom rose
#

Also make sure ground checks are in Update, not FixedUpdate

hushed coyote
#
    void FixedUpdate()
    {

        if (onGround())
        {
            inputSpeed = (transform.forward * input.y * speed) + (transform.right * input.x * speed);
            rb.linearVelocity = new Vector3(inputSpeed.x, rb.linearVelocity.y, inputSpeed.z);
        }
    }```
fathom rose
#

Ah no, im tripping. You're ok

fathom rose
hushed coyote
fathom rose
#

one sec

hushed coyote
#

btw, this worked fine when I tested it on a plane

#

and when the terrain is not flat it also works fine

fathom rose
#
public float lineLength = 5.0f; 
public Color lineColor = Color.red;

    void OnDrawGizmos()
    {
      
        Gizmos.color = lineColor;
        Vector3 startPosition = transform.position;
        Vector3 endPosition = startPosition + Vector3.down * lineLength;
        Gizmos.DrawLine(startPosition, endPosition);
    }

// I draw mine like this

hushed coyote
#

I tried using Gizmos.DrawLine with transform.position as origin and hit.point as end and now I have a line from player to 0 0 0

#

okay, looks like I found a fix to this

fathom rose
#

For GroundCheck i also recommend making a child on the base of the player

#

i think its up to preference of the designer, but sphere checks work better for me

hushed coyote
#

I moved my player to layer 2 (Ignore Raycast) and moved the origin of the raycast to transform.position + new Vector3(0,1.75F,0) because 1.75 is the height of my collider

zenith acorn
#

I'm not sure why that happens ๐Ÿ˜ญ

rain minnow
simple void
zenith acorn
#

wait for some reason jn when I checked it was fine but when I changed scene and come back the panel became a cross instead

leaden ice
zenith acorn
#

okiee

leaden ice
#

and the red X means your object has a negative height or width

zenith acorn
#

I'll try ask there

hushed coyote
#

should jumpForce be in Newtons for rigidBody.AddForce(0,jumpForce,0)?

leaden ice
hushed coyote
#

๐Ÿ‘

#

thanks

leaden ice
hushed coyote
#

oh, got it

#

I'll change it

#

now I understand why I needed to set it to 10000 the jump force with default mode XD

heady iris
#

yes, because an instantaneous force isn't really meaningful

hushed coyote
#

yeah

#

how should I clamp the euler angles of a transform? I tried using Mathf.Clamp but it's doing weird things

vestal arch
#

how exactly are you trying to limit the rotation?

hushed coyote
#

my code is this```c#
private void MoveCamera()
{

    switch (type)
    {
        case MovementType.FixedToBody:
            transform.Rotate(0,input.x * sensibility.x, 0);
            cameraTransform.Rotate(new Vector3(- input.y * sensibility.y, 0, 0));
            break;
        case MovementType.Free:
            cameraTransform.Rotate(- input.y * sensibility.y, input.x * sensibility.x, 0);
            break;
    }
    cameraTransform.rotation = Quaternion.Euler(Mathf.Clamp(cameraTransform.rotation.eulerAngles.x, -90, 90), cameraTransform.rotation.eulerAngles.y, cameraTransform.rotation.eulerAngles.z);
}
leaden ice
#

You cannot isolate individual euler angles and hope for a sensible result.

hushed coyote
#

the input is a Vector2 variable read from Input system

leaden ice
#

yep, - store float variables and clamp those

#

instead of reading the current back from the Transform

robust dome
#

agreed

hushed coyote
#

so store the angle and set the stored values directly?

robust dome
#

clamp the float instead

hushed coyote
#

yeah, that was part of "store the angle"

#

I mean store the clamped angle and then set it to the quaternion without reading the current angles

robust dome
#

the input is a Vector2 variable read from Input system << this needs to be clamped

hushed coyote
#

but it goes from -1 to 1

#

they are the values returned by joystick

spare dome
#

I'm trying to figure out how to cache Randomhide to make sure it cannot pick its current index again (line 122 to 133), can anyone help me out? Yes I know the code is horrid, I will try to optimize it later if I can.
https://paste.ofcode.org/FaavNFQGVQ7G6yGKeVmkjc

hushed coyote
#

Thanks, now the camera is working perfectly

vestal arch
#

also consider shuffling instead of randomly choosing, dependng on what you're using it for

spare dome
hybrid thicket
#

I am going to create an inventory system for my game. I tought that system for it:

Every slot will have an ID.
Every item will have an ID.
The slot will check if there is any item (ID) placed into slot.

However, I am stuck because I cannot figure out how to assign an ID to each slot, so that the player can select the slot by pressing a number on the keyboard or clicking it with the cursor. Can you help me with my issue? Also, please suggest a better system if you have one

eager tundra
hybrid thicket
steady moat
hybrid thicket
steady moat
hybrid thicket
#

20 slots in total

robust trout
#

hey! I made an animationw here my characters arms raise above their heads in my first person game. but as you can see their hands kind of get clipped off weirdly. is the only fix for this moving the camera to a better spot or can I somehow allow the full arms to be rendered regardless

heady iris
#

The meshes are getting too close to the camera.

#

This is determined by the near clip distance on the camera.

#

You can reduce this distance, but if you don't reduce the far clip as well, you'll lose some depth precision

#

so z-fighting will happen more frequently with nearly-overlapping surfaces

#

I do find the default values (0.3 and 1000) to be pretty conservative

robust trout
#

oh yeah reducing that fixes it

#

thanks!

wicked seal
#

hello! Happy christmas everybody. I've got a quick question, does PrefabUtility work when running the compiled build?

heady iris
#

No. Nothing in UnityEditor exists in the built game.

#

Prefabs barely exist in the built game at all!

#

(as as concept, at least)

quartz folio
#

Yeah, they're just instances at that point

heady iris
#

instances that live in the Negative Zone, but instances nonetheless

quartz folio
#

Kinda annoying lesson to be learnt where creating a large prefab base to have loads of nested prefabs on top of is a bad idea

#

because the base is just baked into each of them

heady iris
#

i mean, that's a given

#

I guess you wind up with a little more serialized data than you'd expect?

quartz folio
#

Yup

heady iris
#

especially if you have components that store giant binary blobs inside themselves

quartz folio
#

I made a card game once with lots of variants of animated 2D sprites and the variants bulked out the game something insane

#

had to make a system to manually spawn the base object to avoid having massive things which are just variants

heady iris
#

how did you wind up with sprite data inside of the prefab assets?

quartz folio
#

complex animated sprites can serialize a lot of settings and hierarchy which ends up adding up

#

and UGUI was involved too

#

and it's just as bad

long bison
long bison
#

sorry, I wasn't sure, there are a lot of rules for this server and it seems very strict so I don't want to mess things up

cosmic rain
long bison
#

alright thanks!

cosmic rain
#

Besides, if there's a blatant issue, the community members would likely guide you in the right way to address it.

long bison
#

alright, sounds better than other servers I've been in, last question, I should make a thread for my issue right? I'm only asking because I see some coding questions not as threads in the channel

cosmic rain
long bison
#

alright, thank you again

compact spire
#

I should be able to just import whatever nuget packages to my unity project through my IDE right?

cosmic rain
#

You import packages into unity via the unity package manager.

compact spire
#

hmmmm ok, my issue with Rider forgetting the only package I have installed is unrelated then.

zinc parrot
#

So I am filling out a nativearray in editor, and taking it with me into playmode, but I think unity thinks this is a memory leak, so it yells this at me. is there a way to stop it from yelling at me? I FULLY intend to take the nativearray created in editor and its contents over into playmode

cosmic rain
#

To put it simply, you can't keep the same native array alive between editor and play mode.

zinc parrot
#

So
Why does the data stay?

#

Why can I still access it in play mode without recreating it?

cosmic rain
zinc parrot
#

Fair

#

Ill check it tomorrow thanks

pearl burrow
#

hi guys how would you manage this skill tree

in have 5 different counter. each count how much ive spent in a category. Now each skill to be unlocked needs to meet the requirement of "spend 10 in category1, 20 in category2" and so on and this check should be done every time i upgrade a skill in a category (upgrading a skill means spending in a category).
Should i store all the unlocked skills in a list and iterate through them? i have atleast 50 skills so it seems wacky to me to iterate through 50+ elements every time i upgrade. I was thinking about firing an event from each skill so that they check the requirement by itself but then i need a reference to the skillmanager to unlock the skill

#

maybe a coroutine that checks that?

chilly surge
#

Modern CPUs can easily do millions of instructions per second, checking 50 skills is hardly anything, especially when the check only happens when player upgrades the skill, it wouldn't even be noticeable to the player that clicking the upgrade button is a few nanoseconds slower.

pearl burrow
#

yeah i know this i was just wondering if there is a better way anyway ahah!

#

also the target is mobile (which shouldnt make any difference)

halcyon swallow
#

i dont know what the name for it is exactly but when you "drag a gameobject" into this little box to refrence it (like hinge here)
what is actually going on code wise for this to happen?
is there some other script somewhere keeping track of what object refrences what?

leaden ice
#

The scene or the prefab contains all the information about the objects inside it.

#

when you "drag a gameobject" into this little box to refrence it (like hinge here)
what is actually going on
The reference is being stored in the scene or prefab

#

just like any other values

#

same thing for if you checked that "Closed" checkbox

#

it gets stored in the scene or prefab this object is contained in

cosmic rain
# pearl burrow yeah i know this i was just wondering if there is a better way anyway ahah!

You could implement some smartass way to sort all the skills by the total required points and use a binary search to get to the corresponding skills, then find the one that satisfies each category requirement. But honestly, that would be an overkill.
If you had millions of skills, that might've been worth it, but I probably wouldn't do it even with 1000 or 10000.

cosmic rain
pearl burrow
#

thats totally true

#

sometime im thinking how can i make something better and when you do it you think of it again

clear rampart
#

where do i learn c#

ocean hollow
dense helm
clear rampart
dense helm
#

c# is fairly an easy language. just gotta understand the oop concepts

warm badger
#

how do I strip "STEREO_INSTANCING_ON" from shader? thanks in advance

vestal arch
#

please don't crosspost

amber scroll
#

what?

vestal arch
#

please don't post the same question in multiple channels

hybrid thicket
hardy pasture
#

How to get object facing direction in 2D? My game object isn't rotated at all: in the editor euler rotations show 0, 0, 0 rotations, yet when I'm calling transform.forward.x, it returns 0?
I want to set and get the rotations in 2D with vectors, but if I do transform.forward = Vector3.Left or transform.forward = Vector2.Right, the sprite simply disappears.

zenith acorn
#

I got this error down below while working with navmesh agent

"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination (UnityEngine.Vector3)

#

I already baked the navmesh surface around the map

vestal arch
#

if it's not rotated it'll be (0, 0, 1)

#

you probably want transform.right, and if you want to flip, you could also use localScale.x *= -1

hardy pasture
#

I first flipped character with scale, then switched to using euler angles but I think it's better to work with vector, because I often want to use if character is facing left or right

#

I used a separate variable for that, but transform.right and working with the vector should allow to get rid of that
And use nice math functions like Math.Sign(transform.right.x)

vestal arch
#

i think it's better to work with vector
this.. doesn't really mean anything

#

scale and euler angles are also vectors

#

a vector is just a list of numbers

hardy pasture
#

I mean the geometry direction vector

vestal arch
#

...so, transform.right?

hardy pasture
#

Yep

vestal arch
#

im not sure i'd call that a geometry direction

#

just the direction of the game object

#

i mean it still kinda is an euler angle

#

and underlying it all, rotation is a quaternion

hardy pasture
#

Sure, I just think math and code is much simpler while working with vectors

onyx cypress
onyx cypress
leaden ice
#

Where does that live?
Which object did you reference in the inspector?

leaden ice
onyx cypress
#

scene

onyx cypress
leaden ice
onyx cypress
leaden ice
#

Show the code I mean

onyx cypress
#

of the stick collecting

leaden ice
onyx cypress
#

here

leaden ice
# onyx cypress

well for one in the other script you're multiplying the increase amount by Time.deltaTime;

#

which means it is going to increase by a very small amount

leaden ice
#

and then in this script you're decr3easing by FireDecreaseNumber EVERY FRAME

#

mneaning it will decrease very quickly

#

you put deltaTime in the wrong place

#

it should be used in FireFadeAwaySticks, not in the other script.

onyx cypress
#

ok so time.deltatimeshoud be used infirefadeawaysticks no the other one?

onyx cypress
leaden ice
#

that makes no sense

#

if anything it will make it decrease slower

onyx cypress
#

i multiply iot to the newscale

vestal arch
#

Time.deltaTime controls rates, it's seconds per frame, you use it to control how fast something happens

#

you don't multiply it onto a the scale directly, that would just make it tiny

leaden ice
vestal arch
#

you'd have to multiply it on a rate of change of scale

leaden ice
#

transform.localScale -= Vector3.one * ireDecr3easeNumber * Time.deletaTime; this is what you want @onyx cypress

onyx cypress
leaden ice
#

You tell me. What's wrong with it?

onyx cypress
#

the thing stilld oesnt increase

leaden ice
#

This code has nothing to do with increasing anything

onyx cypress
#

cuz i removed time.deltaTime

leaden ice
# onyx cypress

First step is to use Debug.Log and make sure that line of code is actually running

#

and you can print the value out too

#

to ensure it is increasing

#

you can print the value before and after the line that increases it, to see what's happening

onyx cypress
#

so when i debug it shows maybe it st increasing very little

leaden ice
#

it is increasing by exactly the amount you told it to

#

But why are you saying "maybe"

#

if you logged it, you would know for sure.

onyx cypress
#

yea it is

#

but its not that small of a numebr it wouldve made a different to the vector by increasing it

twin path
#

Anyone that understands about 2D and tilemaps can give me a hand?

vestal arch
twin path
#

I cant spawn the guards on the right place The guards on the top spawn perfectly but not the ones on the bottom. My code is in the .txt message. I really dont know why it's not detecting the tile map sideways but detects upwards

onyx cypress
vestal arch
twin path
#

I do believe its somewhere on the "FindNearestMiddleofRoad" function, I just put the rest so you guys can understand the rest. But where exactly I dont know. Cause I asked chagpt to do this, I dont really know the syntax to do stuff on tilemaps

vestal arch
#

there's nothing special with tilemaps in regards to syntax

twin path
#

I've been like 5hrs trying to figure out what is wrong there

vestal arch
#

what exactly is the issue?

#

like what's the expected vs the actual behavior?

twin path
#

What I wanted was for the guards on the bottom to go to the right side (on this case)

#

And for some reason it's not detecting the tile map sideways

twin path
vestal arch
#

those are just.. method calls

#

what context is this even in? spawning? pathfinding?

leaden ice
#

show the value of the thing you are increasing before and after

twin path
vestal arch
#

just not in the right spot
....so, they aren't spawning correctly, then?

twin path
#

yes, but because of the pathfinding, because it does not detect the tilemap

vestal arch
#

....do you know what pathfinding means

#

pathfinding doesn't really have an effect while spawning

twin path
#

maybe I do not

vestal arch
#

what's the expected behavior?

#

where should they spawn?

onyx cypress
leaden ice
onyx cypress
leaden ice
tawny elkBOT
leaden ice
#

no?

#

I don't see a problem here.

twin path
onyx cypress
leaden ice
#

"doesn't work" is extremely vague, but yes, the problem must be elsewhere

onyx cypress
#

and u said the other one is fine and same with this one

leaden ice
#

Well you still haven't explained what the problem is so

#

that's step one

onyx cypress
#

it says the x, y and z transforms is increasing by 0.10 in debug.log but isnt actuallt increasing in the fieplaces transform component

leaden ice
#

Well which object is that script actually attached to?

#

because that's the one it will scale

onyx cypress
leaden ice
#

Then why would the fireplace scale?

onyx cypress
#

wait do tou mean the firefadeaway? if so it in the logs script other one is in player to collect sticks

leaden ice
#

I mean whichever script has transform.localScale = ...

#

that's going to change the scale of the object that script is attached to

onyx cypress
#

oh ok

#

so thats the on with the logs

vestal arch
twin path
#

Like the tilemap of the road its all the same, and its just the road, the rest like decoration and stuff are on another tilemap, the tilemap of the road as the tag "path". And I'm going to debug everything again after I eat lunch and I'll let u know

quasi elbow
#

were do I go to find help with animation masks issue?

onyx cypress
leaden ice
#

"the logs" is not a GameObject

onyx cypress
onyx cypress
leaden ice
#

that's your variable

onyx cypress
onyx cypress
onyx cypress
leaden ice
#

IDK what "logs" are in your game

knotty sun
#

then go use Unreal, good luck with that

onyx cypress
narrow sapphire
#

Yeah blueprint no thanks

knotty sun
#

love the way people seem to think that stitching a few 3rd party blueprints together is actually game dev

crisp minnow
#

Been a few months of redoing prototpe code and extending some functionality / updating personal packages and now I realise the code works like a labyrynth of delegates awkwardsweat Time to shoot it in the face and redo the plumbing, tear out 90% of delegates and just keep the necessary ones cause this has gotten hard to follow

narrow sapphire
#

Honestly completely redoing entire projects if youโ€™ve been learning how to do what you want but it ended up messy is a fine idea

#

Itโ€™s a lot easier to just write new stuff than refactor the entirety of your code base tbh

#

Just have the old solution open on another vs window and copy paste anything you can

crisp minnow
#

Yeah I share that sentiment but even in this state the code base is several times cleaner than what I have to deal with at work. I just have too many decouplers for components that clearly depend on each other to work, so welding them back together and redoing the flow should not be too hard and will read much better ๐Ÿคž

raven basalt
#

Is calling a method in fixed update the same as calling a coroutine that includes yield return new WaitForFixedUpdate();

Is there any slight differences?

leaden ice
zinc parrot
leaden ice
zinc parrot
#

cuz its up to gigabytes of data

leaden ice
#

What is the use case?

zinc parrot
#

and it can be many many many many files

heady iris
#

you still haven't shown us what you actually did

zinc parrot
#

custom BVH for SW raytracing

#

thats fair!

leaden ice
zinc parrot
#

yes but it can take several minutes to fill it out

#

so I would rather do it just once in editor, then be able to go into play multiple times

raven basalt
#

I am trying to create a coroutine that causes the enemy to detect any thing tagged with obstacle around it, and if there is an obstacle around the enemy, it causes the enemy to jump. However, it is not working properly:

    private IEnumerator CheckForObstacles()
    {
        while (true)
        {
            // Only check for obstacles if the enemy is grounded
            if (isGrounded)
            {
                // Perform a CheckSphere to detect obstacles within the specified radius
                Collider[] hitColliders = Physics.OverlapSphere(transform.position, obstacleCheckRadius);

                foreach (Collider hitCollider in hitColliders)
                {
                    if (hitCollider.CompareTag("Obstacle"))
                    {
                        isJumping = true;
                        // Apply an upward force to make the enemy jump
                        rbody.AddForce(Vector3.up * jumpForce, ForceMode.Force);
                        Debug.Log("NoAirMoveObstacleSimpleSlopeMeleeEnemyController: jumpForce has been applied");
                        
                        break; // Exit the loop after detecting the first obstacle
                    }
                }
            }

            // Check if the enemy is in mid-air and set isJumping to false
            if (isJumping && rbody.velocity.y <= 0) // Enemy is falling or has reached the peak of the jump
            {
                isJumping = false;
            }

            // Wait for the next fixed physics update
            yield return new WaitForFixedUpdate();

            // Wait for the next frame (LateUpdate)
            //yield return null;
        }
    }

zinc parrot
#

not quite sure what to show tbh
I just create the nativearray in editor with persistant allocator and fill it out

leaden ice
raven basalt
leaden ice
zinc parrot
#

WAIT I DONT ACTUALLY NEED THIS ARRAY IN PLAY!
probably why I thought it was working...

#

wait but I do
Heck I am probablyt able to dispose it but still use the allocated pointer... to read into technically uninitalized data that just happens to still contain the data for the array

heady iris
#

โœจ

leaden ice
#

That sounds like begging for trouble tbh

zinc parrot
#

I agree

#

I am fixing that now

#

do I need to deallocate pointers themselves?

#

I dont think so but just to be safe
But the entire reason I went to native was because I got so sick and tired of half my RAM use being reserved memory, since i do most of the ram heavy work in editor, it has some difficulty freeing it

raven basalt
#

The couroutine is running

isGrounded is true, but the enemy just hovers instead of jumping

The overlap sphere hits all the objects that is within it, but it only does anything if the collider has a tag of obstacle

heady iris
zinc parrot
#

I was profiling using the memory profiler

heady iris
#

okay, but were you having any kind of problem?

zinc parrot
#

no cuz I have 64 gigs of ram, but I do NOT trust windows/unity to free that reserved ram if needed in editor

heady iris
#

i wouldn't re-architect a bunch of my code to solve a problem that doesn't currently exist

zinc parrot
#

well since this is meant to be used by others mostly... I cant really ignore possible problems

#

since I have 64 gigs of ram, its unlikely ill normally run into RAM problems, but 64 gigs of ram is an uncommon case

knotty sun
zinc parrot
#

eh its enough for me

#

im more limited by my poor r5 3600

heady iris
#

perhaps if you're trying to run five different CAD programs simultaneously

knotty sun
heady iris
#

I don't see how that's relevant to what you claimed

#

obviously, no modern operating system is operating in real mode

knotty sun
#

You're talking about programs, I'm talking about the data (and thus the ram) they require

somber nacelle
#

I have 32gb RAM, and virtual memory (the page file) on my device disabled. It is plenty for developing in unity or just multitasking in general. it's a bit ridiculous to insist that 64gb is not enough and that virtual memory is a must in this case

heady iris
#

(well, you're always using virtual memory, since you are not operating in real mode -- you are simply not having to page anything out to disk)

#

I still have no clue where this assertion about 64 of god's-own gigabytes not being sufficient is coming from

knotty sun
#

Depends what you are doing, open a few Unity projects, blender models, gimp images + browser pages + Discord (not to mention the OS itself)

narrow sapphire
#

Heโ€™s not running windows off a floppy disk is he

latent latch
#

not everyone uses chromium browsers

#

also cutting back vs for vs code saves you like 4 gigs

crisp minnow
#

I'm going strong on 16 at home and our work mini M1s I believe come with 32 and they're definitely not struggling on that with multiple 3d and asset heavy projects open. That's a wild claim ๐Ÿ˜…

wheat spruce
#

weird, for some reason visual studio has stopped showing errors

vestal arch
#

!vs

tawny elkBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

โ€ข Visual Studio (Installed via Unity Hub)
โ€ข Visual Studio (Installed manually)

wheat spruce
#

I dont think thats the issue, its not that its not showing up only for unity stuff

#

This should be showing up as an error

vestal arch
#

what error are you expecting

wheat spruce
#

Center and Size havent been defined

vestal arch
#

you sure they aren't just defined on IShape?

wheat spruce
#

they arent

#

this also should have an error because I havent implemented anything from IShape

vestal arch
#

try hovering center/size/ishape and see where it brings you

wheat spruce
#

Assets\Source\Geometry\Shapes\PolygonShape.cs(5,32): error CS0535: 'PolygonShape' does not implement interface member 'IShape.GetBoundingBox()' unity registers the error just fine

vestal arch
wheat spruce
vestal arch
#

does restarting work?

#

does restarting the language server work? (if that's a thing you can do on vs)

wheat spruce
#

restarting VS seemed to fix it

vestal arch
#

box of black magic moment

wheat spruce
#

im not keen on "turn it off and on again" being the fix

vestal arch
#

i mean if it happens again then maybe there's a deeper issue

#

but if it's a one-off then.. i mean, stuff can be finicky sometimes

somber nacelle
#

reloading the solution/project would have fixed that as well. it's just that restarting visual studio obviously does that too

wheat spruce
#

I wonder if theres already a basic geometry library, would save me the hassle of trying to implement it myself

vestal arch
#

there most likely is

wheat spruce
still ermine
somber nacelle
robust dome
#

lel

#

good catch

wheat spruce
#

aaand VS isnt giving errors anymore

somber nacelle
#

make sure visual studio is up to date. it seems like you're experiencing an issue that was fixed in a recent update

wheat spruce
#

just checked, it says its up to date

#

what the hell, the errors just appeared without me doing anything

vestal arch
#

lsp loaded

knotty sun
cursive granite
#

How would I go about being able to place cheese?
Essentially I have a plate with a burger patty on it and a drawer where the cheese sheets are in. I have gotten to the point, that the player can open the drawer and take cheese from it, but how can I allow the player to place it on the burger patty in a way that is "snapping" to it and becomes a part of the burger patty?

cursive granite
#

what after that?
I can detect the raycast collision but what would I do with it?

#

I want to make one burger object out of the bun gameobject and the cheese gameobject when I decide to interact

rigid island
cursive granite
#

that is a thing? Parenting things to an object via script? That sounds useful

rigid island
#

anything you can do normally in unity edit mode, can usually be done in runtime including parenting objects

#

you dont have to create a whole new gameobject

zinc parrot
#

so I found this... interesting asset in my folder... is there a way to check a mesh to see if it has no triangles, without calling mesh.triangles.length?(since thats very expensive for a simple validity check...)

cursive granite
#

hmm that is great news.
So I would just specify the two objects (base object and holding object), make the holding object a child object of the base and then specify the offset? Sounds simple, what could go wrong ๐Ÿ’€

cursive granite
#

great thanks.
I swear the people on this server are all just good people. Thank you all

rigid island
#

I prefer can also work because of this This method is the same as the parent property except that it also lets the Transform keep its local orientation rather than its global orientation. This means for example, if the GameObject was previously next to its parent, setting worldPositionStays to false will move the GameObject to be positioned next to its new parent in the same way.https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Transform.SetParent.html but yeah .transform can also work

This method is the same as the parent property except that it also lets the Transform keep its local orientation rather than its global orientation. This means for example, if the GameObject was previously next to its parent, setting worldPositionStays to false will move the GameObject to be positioned next to its new parent in the same way.

cursive granite
#

good as in nice or kind

#

when it comes to coding, we are all terrible sadok

knotty sun
wheat spruce
leaden echo
#

Hello guys, I started out recently,
I am making a node based game and I am doing the movement with vector3.lerp.
Could somebody please help me with implementing a view bobbing effect?
It would greatly enhance the experience.
I would also like to ask if there is any other way to move between two waypoints other than lerp.

soft shard
# leaden echo Hello guys, I started out recently, I am making a node based game and I am doing...

I would imagine there should be lots of tutorials for a view bobbing effect, what have you tried searching up? In terms of movement, there is also .MoveTowards or using physics from a rigidbody, you can also directly set the position, all depending on the kind of movement that you need, and if the movement should care about physical objects like walls, hills, etc - in most approaches, your essentially moving based on a percent value between 0 and 1, where 0.5f is half way or 50% between A and B, how fast that percentage moves from 0 to 1 is up to you, it could be through deltaTime, it could be through an AnimationCurve or some other method, depending on the affect and drawbacks lerp may be having for you atm

leaden echo
#

I searched up multiple tutorials, however every one of them was for a rigidbody. I wanted to make a node-based system where your movement is very limited.
But my camera only bobed when I wasn't moving between waypoints.

#

This is how my movement works:
I am initialy in a center position, here I can press a, w, s or d, pretty generic stuff.
Then if I press a I turn 90 degrees to the left then start moving to a door and then if I press s at there I turn 180 degrees and start moving back to the center position.
Basically while the character was rotating I was bobbing and when the lerping occured nothing was happening even tho I didn't turn off the bobbing myself.

#

Oh yeah and I also tried debugging.
I changed the logic so that I bob my head when I'm not moving and worked perfectly. The camera was bobbing fine. So I'm really close to figuring out what the peoblem is, but I'm unsure as of now.

soft shard
#

Hmm, maybe you can share your code and if not myself, im sure someone might be able to provide some help

brazen nest
leaden echo
#

Alright here is the code piece that does the waypoint to waypoint movement:

System.Collections.IEnumerator MoveToWaypoint(Waypoint newWaypoint)
{
Vector3 startPosition = transform.position;
Vector3 targetPosition = newWaypoint.transform.position;
float elapsedTime = 0f;

    while (elapsedTime < 1f)
    {
        transform.position = Vector3.Lerp(startPosition, targetPosition, elapsedTime);
        elapsedTime += Time.deltaTime * moveSpeed;
        yield return null;
    }

    transform.position = targetPosition; // Biztosan pontos pozรญciรณ
    currentWaypoint = newWaypoint; // Frissรญtjรผk az aktuรกlis waypoint-ot
}
knotty sun
#

So why would you expect this

 transform.position = Vector3.Lerp(startPosition, targetPosition, elapsedTime);

to do any bobbing?

leaden echo
#

Oh I'm sorry, this is not for the bobbing.
This is just the moving I think it would be too big to put every part of my script here.
It's actually quite large.
Unfortunately I cannot even copy the part here that I want, because I'm on my phone and I cannot acces my computer anymore for today.

rain minnow
tawny elkBOT
shell scarab
#

hello, is it a known bug that there is no stack trace for profilers connected to a build or am I being a bit silly (some option I need to enable)? I am getting an error only but without a stack trace, yet when I look in the log file I can see the stack trace.

#

unity 6 recommended LTS

vernal geyser
unique delta
#

Can you freeze a gameobject transform ?

heady iris
#

Don't change it!

#

What are you trying to achieve here?

unique delta
#

in have a player that flips and i want the child to not without making it an idividual gameobject.

heady iris
#

You can't parent an object to another object without being affected by the parent's transform.

#

that's the entire point of parenting

#

You can use the Constraint components to make one object follow another

unique delta
#

I want just the local scale to freeze.

unique delta
heady iris
#

if this is 2D, you can just flip the sprite renderer instead of the entire object's transform

unique delta
#

then i ll just get the object to follow the player trough code

sacred sinew
#

Do you guys prefer to use regular C# events (Delegates/Actions) or Unity Events?

#

I'm kinda confused on them

#

Is it just preference?

cosmic rain
quartz folio
#

There's no reason to use a Unity event unless you want to serialize it

cold parrot
# sacred sinew Is it just preference?

Unity events are 10-100x slower than C# ones. If you donโ€™t know why you would need the Unity Eventโ€™s features (or what they are), use c# events. Using unity events in the editor to hook up systems is a nightmare to maintain but very helpful in prototyping.

heady iris
#

I use Unity events if I explicitly need to hook them up in the inspector

#

I only really do that when I have something really generic that doesn't have more specific code written for it yet

sacred sinew
#

So, I should only use Unity Events if necessary

#

Otherwise, C# events

#

Got it, tks everyone

#

Sorry to ask again but is there an actual use for Delegates over Actions?

heady iris
#

that's a bit of an apples-and-oranges question

#

or maybe a squares-and-rectangles?

#

System.Action is a pre-defined delegate type

sacred sinew
#

From what I've seen, Actions just appear to be a simpler version of Delegates

sacred sinew
#

So they're just a bundle

heady iris
#

You often don't need to define your own delegate types

#

since you can just use the built-in generic ones

#

System.Func<int, int, int> takes two ints and returns an int

#

One big reason to define your own is that you can include parameter names

#

This can make your code easier to understand

sacred sinew
#

I see

#

But if I can understand the built-in generic ones, there's no need to create my own Delegate types

cold parrot
heady iris
#

unless that expands into a genuine multi-parameter delegate type?

cold parrot
#

itโ€™s very similar to what event args would be

heady iris
#

Ah, true

#

since that demands a two-argument function

#

I've also definitely used "func that takes a tuple" more than a few times

cold parrot
#

itโ€™s just a quirk, itโ€™s not really great in practice

#

in cases where you need an args struct, you typically have a better time declaring the struct

raven basalt
#

When I use the debugger in visual studio code, the window with all the variables being tracked is located in this odd position, and I can't add or remove any of the variables. How do I fix this?

scenic pewter
#

I'm making a color switch type game, and this is my circle manager code (circle is the thing with 4 colors that the user has to get through):

using UnityEngine;

public class CircleManager : MonoBehaviour
{
    public float rotations = 100f;
    public float despawnAfterY = 20f;

    private void Update()
    {
        transform.Rotate(0, 0, rotations * Time.deltaTime);

        GameObject player = GameObject.FindWithTag("Player");

        if (player.transform.position.y > transform.position.y)
        {
            Destroy(gameObject);
        }
    }
}

the object rotates, however if the player y position is more than the objects, the object doesn't get destroyed, any reason why?

#

(despawn after y is ignored for testing)

heady iris
#

Figure out what player actually is

#

Perhaps you have multiple Player-tagged objects

#

Consider logging it:

Debug.Log(player, player);

The second argument is the context for the log statement

#

it'll highlight the player object when you click on the log entry

cosmic rain
scenic pewter
proud juniper
#

Do people generally use the UI Toolkit editor and attach callbacks (ie for buttons) to elements with specific IDs or do they construct UI Toolkit UIs programmatically?

zenith acorn
#

I'm new to this and I just did a simple AI navigation with the nav mesh surface

#

However the zombie seems to get stuck randomly even though the surface is flat?

#

Like it just get stuck there for 8 seconds before able to move again

rain minnow
pearl burrow
#

Hi currently in my project i have plenty of gameobject all sharing the same material with the same big texture. whats the difference is that each mesh has its own UV located in different part of the texture. this should help to reduce the draw calls. But now im figuring out that i want some difference between the material, let it be some object must emit light, other must have a different shader. whats the best approach? i currently have two shaders. one is an unlit toon shader with some "windy" effect, another is a just the unlit toon shader one

cosmic rain
pearl burrow
#

but currently im 100+ batches in the stat page, im targeting mobile so i should keep that low. I dont know what to do to optimize more

cosmic rain
#

Are you actually going under the target frame rate budget on your target platform?

#

Are you just optimizing for the sake of optimizing?

pearl burrow
#

actually it runs quite smoothly. Doesnt the increase draw calls reduce performance?

pearl burrow
cosmic rain
cosmic rain
pearl burrow
#

im using a render texture with a low res and i can keep a 60 fps

#

so yeah you re right, just wasting time instead of implementing more things

empty elm
#

I'm trying to convert a class to Json with JsonUtility but its not working. I know instances of the class exist but the string is empty. Any ideas why or any workarounds are appreciated.
*ButtonDisplayable is an interface, so it shouldn't affect whether SimulationRecord can be serialized

[System.Serializable]
public class SimulationRecord : ButtonDisplayable
{
    public int day;
    public int id;
    [SerializeField] private int value;
    public PlayerData playerData;

    public SimulationRecord() {}
    
    public SimulationRecord(BattleData battle, PlayerData player, int id, int day)
    {
        value = battle.value;
        playerData = player;
        this.id = id;
        this.day = day;
    }

*There are some functions here, although I don't think that affects serialization..?
}```

```[Serializable]
public class PlayerData
{
    public WeaponItem weapon;
    public BulletItem bullet;
    public UtilityItem utility;

    public PlayerData(WeaponItem weapon, BulletItem bullet, UtilityItem utility)
    {
        this.utility = utility;
        this.weapon = weapon;
        this.bullet = bullet;
    }

    public int getValue()
    {
        return weapon.price + bullet.price + utility.price;
    }
}```
cosmic rain
empty elm
quartz folio
#

You can't serialize a list as the root of a JsonUtility call

#

You should create a serializable wrapper for the list

empty elm
# quartz folio You should create a serializable wrapper for the list

Itโ€™s a part of another class; SaveData right now. SaveData is an aggregate of several classes that are [serializable], some of them in lists. Everything else is serializing properly except for this class which results in empty list. Sorry for not being clear in my last message

quartz folio
#

Everything looks fine, so can't say what the issue is without more code

cosmic rain
#

We need to see the relevant code and logs.

shell scarab
#

How do I upgrade my render pass/feature to use the render graph features in Unity 6? I tried to look at this documentation, but it seems to not have been updated and just renamed for some reason. You can see it says code with old/code with new pipelines, yet the code with new pipeline uses depreciated methods that are no longe implemented without compatability mode (such as Execute or OnCameraSetup). So how do I do it??

https://docs.unity3d.com/6000.0/Documentation/Manual/urp/upgrade-guide-unity-6.html

I have a few things that are saying they're obsolete, but there seems to be no information on what to use instead (thanks unity).

If anyone has any information, I'd really appreciate that. Here are the things that are obsolete in my script:

  • renderer.cameraColorTargetHandle
  • public override void OnCameraSetup (ScriptableRenderPass)
  • public override void Execute (ScriptableRenderPass)
zenith acorn
#

I keep getting error while using the pool

InvalidOperationException: Trying to release an object that has already been released to the pool.

#

For some reason when I try to release the object it says that it have already been released to the pool?

shell scarab
cosmic rain
zenith acorn
#

for some reason the triggered function got called twice

cosmic rain
wheat spruce
#

I've got this Grid, that uses a Rectangle (from a Spline) to get the dimensions.

public class Grid
{
  public int GridWidth;
  public int GridHeight;
  //Grid will be used for a tilemap

  public Grid(Rectangle rectangle)
  {
    GridWidth = Mathf.RoundToInt(rectangle.Width);
    GridHeight = Mathf.RoundToInt(rectangle.Height);
  }
}```Like this, I'm forced to construct Spline prior to Grid, and Spline **must** have points in order for the bounds to have any side (else I get a 0 size Grid).
#

I can do it that way, but I dislike the sound of that type of dependancy. Could I instead have my Grid use a default value for size when no Spline exists (also when Spline has no points), but once Spline is valid the Grid begins to use it.

soft escarp
#

is this formula: Mathf.Sqrt(2f x JumpForce x 9.81f) only good for 2d platformers or good for any game(3d too)?

wheat spruce
#

I cant see why it would only be good for 2D

leaden ice
soft escarp
wheat spruce
#

What is the purpose of that formula?

soft escarp
leaden ice
soft escarp
leaden ice
soft escarp
wheat spruce
#

I dont think its a bad assumption to think a formula that works with 2D jumping, might not translate to 3D

leaden ice
#

It's a bad assumption because the Y axis is common to 2d and 3d

vestal arch
heady iris
#

you shouldn't even care which axis is "up"

#

you should care about a gravity vector!

leaden ice
#

Well gravity defines what "up" and "down" are.

#

so as long as your gravity vector is aligned with existing world axis(es) then it'll be the same

heady iris
#

I suppose I should say that you shouldn't think of a specific axis is "up"

#

that limits you to axis-aligned thinking

mossy shard
#

Can i get from a grid every cell it has? like it's position and etc?

#

in code obvi

vestal arch
#

are you using a tilemap?

#

afaict grids don't hold stuff themselves, they literally just provide a grid

mossy shard
#

exactly what i needed

#

thanks you ๐Ÿ’‹

wintry crescent
#

is there a way, using the android autoconnected profiler, to get ANYTHING more specific than this?

#

I have no clue what object could possibly have a null reference, since it doesn't happen in editor for whatever reason

little meadow
#

there's the logcat thing... in Window -> Analysis... I don't remember if it required a separate package

#

Android Logcat is the package, yes... it'll have ALL the logs

wintry crescent
mossy shard
#

cause when i try there are not many functions TileBase provides and i can't seem to find the positions for ex

vestal arch
mossy shard
#

wouldn't that work

#

or i get something wrong?

vestal arch
#

Tile does not mean what you think it means

#

Tile isn't on the tilemap

#

it's on your palette

#

same for TileBase or anything that extends it

#

the tilemap has references to the Tiles on the palette

mossy shard
#

then how

#

do i get the postions

#

from the game itself

#

i don't believe a second it's impossible

vestal arch
#

you could use tilemap.cellBounds.allPositionsWithin to get a list of positions, then from those positions you can get the corresponding tile on the tilemap

vestal arch
#

Vector3Ints

#

not quite a list, it's an enumerator

#

you can foreach it

mossy shard
#

for the tilemap i give the grid from the assets then using that list i will gather all the positions from the cells that were made in the game?

vestal arch
#

not sure what you're trying to say there

wheat spruce
#
//class MapComponent
for(int x = 0; x < _grid.GridWidth; x++)
{
  for(int y = 0; y < _grid.GridHeight; y++)
  {
    Map.SetTileColor(x, y, _tileCS, _testRT);
  }
}

//class Map
public void SetTileColor(int x, int y, ComputeShader cs, RenderTexture tex)
{
  GetTile(x, y).SampleColor(tex, cs);
}

```I'm doing this to have my tiles sample from a texture to set their color by sampling a texture. Does it seem like its a good idea to have the MapComponent have to loop over every tile to make them update their color?
leaden ice
wheat spruce
#

Map stores private Tile[] _tileMap; and has a handful of methods to interact with the array

#

SampleColor runs a shader that takes the tiles position, and finds out where that is in a texture, the shader returns the color from the texture

#

currently theyre all black as I havent got the sample code working correctly. But when a texture is provided these tiles will change their color to match the texture at their location

leaden ice
wheat spruce
#

yeah, because I need to sample the texture

leaden ice
#

Can't you just have the texture read/write?

#

gpu->cpu is slow

wheat spruce
#

using the cpu to find the pixel color is even slower

#

I'll try it and see

#

but generally its not something I'd want to do

#

actually nah, its just going to be a headache to test it out, and besides I'd rather just do all texture related operations on the gpu, thats what its there for

mossy shard
leaden ice
#

You should do one shader call for the whole texture

wheat spruce
#

Thats mostly a result because im working with each Tile individually

#

I guess I could have the Tilemap sample the texture and return the buffer with all the different color values that it found

earnest gazelle
#

Hey, how can I prevent others from merging the main branch into the feature/bugfix branches?

mossy shard
#

Would this code work for getting from a tileMap the position of every tile?

public class Grid : MonoBehaviour
{
    public BoundsInt area;

    [SerializeField]
    Tilemap tilemap;

    public Node[][] openList;

    void Start()
    {
        int xMax = area.xMax;
        int yMax = area.yMax;

        openList = new Node[xMax][];

        for (int i = 0; i < xMax; i++)
        {
            openList[i] = new Node[yMax];
        }
    }

    public void setGrid()
    {
        int i, j; i = j = 0;

        foreach (Vector3Int tile in tilemap.cellBounds.allPositionsWithin)
        {
            openList[i++][j++] = new Node(tile.x, tile.y);
        }
    }

}

#

i wanna know if i work for nothing or not

robust dome
#

how about testing it out

mossy shard
#

it would just spit out random numbers

wheat spruce
#

my Tilemap now just returns the array of colors that get applied to my Tiles

#
void SampleMap(uint3 id : SV_DispatchThreadID)
{
  float2 uv = float2(id.x / (float)GridWidth, id.y / (float)GridHeight);
  uv.x *= (float)TextureWidth;
  uv.y *= (float)TextureHeight;
  float4 color = Map[uv];
  Result[id.y * GridWidth + id.x] = color;
}```technically the GPU *does* go pixel by pixel, but it does several pixels in parralell so its way faster than the CPU that just goes one by one
#

I wonder if its worth giving my Tiles actual world coordinates. Right now they only hold their XY position in the grid, but having a Vector3 of where they actually exist could be useful

onyx cypress
flint plume
onyx cypress
flint plume
onyx cypress
flint plume
#

so you need to add a limit to the .Chase() time then?

hexed pecan
#

Are those logs getting printed?

onyx cypress
onyx cypress
hexed pecan
#

If the logs are printing it means that Chase/Wander are getting called correctly

#

So your issue is likely on the EnemyAI side

soft shard
# earnest gazelle Hey, how can I prevent others from merging the main branch into the feature/bugf...

Why would anyone WANT to merge the main branch into another? Usually its the other way around, other branches get merged into main when ready - although maybe this might help? https://graphite.dev/guides/prevent-merge-without-review-github - essentially you may have to setup "rules" on the branch that require a "review request" that you can either accept or block before a merge can (or cannot) happen

Graphite.dev

This guide provides step-by-step instructions on setting up GitHub to prevent merging pull requests without proper reviews.

leaden ice
#

Very often merge our main branch into features and staging to pick up upstream changes

soft shard
#

Really? Interesting, I usually use the main branch as a "stable and shippable" version, where everything eventually gets merged into it, I seen some workflows that use the main as a "RC" (Release Candidate) with a similar idea where features are made from branching the RC, doing work, having it reviewed, then merging back into RC at the next milestone

hexed pecan
#

Debug it

leaden ice
#

Otherwise we end up with too many conflicts

onyx cypress
# hexed pecan Debug it

im sure its not the enemy ai i debugged it it probably the collider in the other script but im not sure hwat im doign wrong

shell scarab
#

how do i switch between these at runtime? There seems to be absolutely no way but then why would this list exist?

heady iris
#

It's actually chosen on the camera.

#

See the Universal Additional Camera Data component

soft shard
heady iris
#

(you can also just rebase so that it looks like your feature branch was just branched off from main, of course)

leaden ice
soft shard
#

Ah, interesting, that makes sense

heady iris
#

i cleaned up your repository by rebasing each day's changes into one commit

#

โœจ

soft shard
leaden ice
#

It's always production worthy on main

#

Also we use mono repos so not everything is related

shell scarab
leaden ice
#

Or part of the same deployable

shell scarab
#

hundreds of commits each day to main sounds horrible

leaden ice
#

I thought so too but we have a very good devex team so it works

heady iris
#

hundreds of commits to the same files would be horrible

#

that'd be a battle royale

shell scarab
#

well, I never want to see the history tree of a repo with hundreds of commits to main per day

soft escarp
undone folio
#

Trying to spawn an enemy randomly to the left and right, but it ONLY spawns to the left. "spawnitem" always returns 1. even after 20 tries ```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class spawnmaster : MonoBehaviour
{
// Start is called before the first frame update
public static int spawnpoints;
private float clock = -1;
private int spawnitem;
public GameObject objectToSpawn;
public GameObject spawnLeft;
public GameObject spawnRight;
void Start()
{
spawnitem = Random.Range(1, 2);
spawnpoints = 20;
clock = 5;
}

// Update is called once per frame
void Update()
{
    
    if (clock > 0)
    {
        spawnitem = Random.Range(1, 2);
        clock -= Time.deltaTime;
    }
    if (clock <= 0)
    {
        
        clock = Random.Range(3, 7);
        Debug.Log("Clock = " + clock);
        if (spawnpoints > 0)
        {
            
            

            if (spawnitem == 1)
            {
                spawnpoints -= 1;
                Instantiate(objectToSpawn, spawnLeft.transform.position, spawnLeft.transform.rotation);
                
                Debug.Log("spawnitem = " + spawnitem);
            }
            if (spawnitem == 2)
            {
                spawnpoints -= 1;
                Instantiate(objectToSpawn, spawnRight.transform.position, spawnRight.transform.rotation);
                
                Debug.Log("spawnitem = " + spawnitem);
            }
        }
    }
}

void Spawn()
{

}

}

soft escarp
#

change it in the start and update

somber nacelle
rain minnow
soft escarp
rain minnow
soft shard
lethal tapir
#

using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;

public class MyJobSystem : MonoBehaviour
{
[BurstCompile]
struct MyJob : IJob
{
public int a;
public int b;
public NativeArray<int> result;

    public void Execute()
    {
        result[0] = a + b;
    }
}

void Start()
{
    NativeArray<int> result = new NativeArray<int>(1, Allocator.TempJob);
    MyJob job = new MyJob
    {
        a = 5,
        b = 3,
        result = result
    };

    JobHandle handle = job.Schedule();
    handle.Complete();

    Debug.Log("Result: " + result[0]);
    result.Dispose();
}

} what the role of NativeArray<int> is in this context?

chrome berry
#

If I have Foo<T> as a generic class, and SomethingFoo : Foo<Something> as a derivation
In Foo<T> is a reference protected static Foo<T> singleton, can I cast that to SomethingFoo ?

tawny elkBOT
steady moat
rain minnow
chrome berry
steady moat
# chrome berry I have a singleton archive class that stores references to scriptable objects of...

Yeah, use something like:

public abstract class Manager : MonoBehaviour
{
    public abstract IEnumerator InitializeAsync();
}

public abstract class Manager<T> : Manager
    where T : Manager<T>
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
    private static void Init()
    {
        Instance = null;
    }

    public static T Instance { get; private set; }

    private void Awake()
    {
        if (Instance != null)
        {
            Debug.LogError($"There is already an instance of {nameof(T)} in the scene at {Instance.transform.GetFullPath()}. Replacing it.");
            Destroy(Instance.gameObject);
        }

        Instance = (T)this;
    }
}
#

Your instance would be of the type of the manager instead.

#

public class GameFlowManager : Manager<GameFlowManager>

#

GameFlowManager gameFlowManager = GameFlowManager.Instance;

undone folio
#

@soft escarp THANK YOU, it works

chrome berry
#

And then I can do GameFlowerManager.Instance.DoSpecialThing(); if DoSpecialThing() is a method in GameFlowManager?

chrome berry
#

I'll give that a try!

chrome berry
tawny elkBOT
chrome berry
#

Actually, lemme pastebin what I have for more context

#

I didn't post any large code block though?

steady moat
#

I was asking for the code. If it is long use a pasta site

#

otherwise you can post it here.

chrome berry
steady moat
#

Your constraint is wrong

#

public abstract class Manager<T> : Manager where T : Manager<T>

#

See what I used.

chrome berry
#

No no, I'm showing what the class I had is. Yours doesn't have a type constraint for the type of scriptableobject being stored, so I'm asking how yours would work with what I need to achieve

steady moat
#

Yeah, then you would want to have an other constraint

#

With an other generic parameter

chrome berry
#

Because I have multiple of these archives, for each kind of scriptable object
I'll rewrite mine again to fit your set up, add in the constraint, and then provide the error I'm getting with that

steady moat
#

public class AssetArchive<T, U> : MonoBehaviour, IArchive where T : UnityEngine.Object, U : AssetArchive<T, U>

#

Soemthing like that.

#

Also, I do believe you might want to use Addressable for what you are doing. You might not see it now, but down the line you are going to have loading/memory issue with what you are doing.

chrome berry
#

Would storing references to all my SOs be a performance hit on memory?

steady moat
#

Yes

#

You are going to load all the SOs whenever you load the object that have a reference to the object that holds everything.

#

That means also all the image, meshes or animation that are associated.

#

As you are going with things, that would mostly be your entire game.

#

Wont matter if the game is small though.

chrome berry
#

In this case the SOs being referenced have no meshes, animations, etc. Just value type data, and some small sprites (32x32 max)

#

But, I should look at adressables anyways just to understand that system

steady moat
#

Also, addressable is basically what you are doing at the moment.

#

You can load your asset by name or by label from anywhere.

#

Every call to GetAssets would mostly be a call directly to addressable

#

Example of getting all the statistics the game owns.

private Dictionary<string, StatisticDefinition> statisticDefinitions = new Dictionary<string, StatisticDefinition>();
private AsyncOperationHandle<IList<StatisticDefinition>> statisticsHandle;

public override IEnumerator InitializeAsync()
{
    statisticsHandle = Addressables.LoadAssetsAsync<StatisticDefinition>("Statistic", (StatisticDefinition statisticDefinition) => statisticDefinitions.Add(statisticDefinition.HumanReadableId, statisticDefinition));
    yield return statisticsHandle;
}

private void OnDestroy()
{
    if (statisticsHandle.IsValid())
        Addressables.Release(statisticsHandle);
}
chrome berry
#

Thanks, diving into the addressables documentation

bleak olive
#

I'm beyond brain explosion, yes I know there is a networking section for this but I don't think it should go in there.
I'm using a template in Unity that has multiple scenes that handle networking, and one of them named "Bootstrapper" for some reason. Before I press "Start Game" for multiplayer, it spawns the player, and for the level, it needs multiple spawn point so nobody spawns inside of each other, problem is, all the spawn points are specific to each scene, maybe I could fix it by moving the player spawning to be AFTER the scene loads but that's a lot of re-writing.
What should I do? I'm using Fishnet btw

#

This is a big project, and I've just switched from Godot, so please talk to me like I'm stupid

bleak olive
#

How it's structured after creating lobby and loading game scene

pulsar ocean
warm rover
#

is there any way to export a navmesh off mesh links to get the start and end pos i cant find anything even on the docs

fleet gorge
#

I'm confused with what you wrote

#

Do you want to change the player spawn location?

fleet gorge
mossy shard
#

does CheckSphere work for a 2d space if i got my z 0?

#

cause it will take just a circle right?

latent latch
#

any reason to not use the 2d physics methods

mossy shard
#

it works perfectly

#

thank u

#

didn't know 2d had these methods

latent latch
#

It's a whole different physics library Unity uses called Box2D

mossy shard
#

i see

#

sank u

sullen drift
#

hi guys, so im making a scope using camera renderer. The problem is, some of the objects cannot be seen through the scope (in this example, the green table is not showing in the scope even though i already iclude the culling mask to everything for the scope camera)

#

ahh nvm, found the problem

pliant rivet
#

Hey guys, has anyone taken unity certified professional programmer exam? i am planning to take the exam and i had few questions about it..

sullen drift
#

me

#

i already got the certification

pliant rivet
sullen drift
#

sure

pliant rivet
#

okay

fleet gorge
#

I'm considering taking professional

pliant rivet
#

actually i am unable to find the exact structure of the exam, it's overall syllabus which it covers (it is provided in a high level way) and the learning resources for it. I saw that packt publishing has a nice book for the exam

fleet gorge
pliant rivet
#

i see.. how many questions?

fleet gorge
#

60? 70? I can't remember

pliant rivet
#

hmm and it was 1hr 45 min? did you do it on the pearson portal?

fleet gorge
#

It'll definitely be shorter than 1h45 min

pliant rivet
#

okay

fleet gorge
#

You can leave when you're done

pliant rivet
#

what about the syllabus and learning resources?

#

the syllabus is very abstract

fleet gorge
#

As long as you use unity a good amount you'll be fine

pliant rivet
#

that is nice

#

i have made some games with unity so i should be fine then. any course which you recommend?

fleet gorge
#

Course? I don't think there's any course to let you study in particular for the exam, as long as you know intermediate c# programming, ienumerator and jobs, unity UI, UI toolkit, old and new input system you should be fine

pliant rivet
#

okay thanks a lot

sullen drift
#

same, i would reccomend what @fleet gorge said

#

also dont forget about design patterns and optimizing codes