#archived-code-general

1 messages Β· Page 419 of 1

limpid siren
#

it's weird because it's set to don't sync

#

but according to the profiler it was doing vsync

rigid island
#

make sure your Selected graphic /quality setting is the one you're using in the editor

#

unity made it a bit confusing there

#

the lightest gray one means its the one selected

limpid siren
#

yeah it should be the right one

#

I deleted the other quality settings just in case, and it's still doing the the vsync despite being set to don't sync in the settings

rigid island
#

thats odd

#

are you doing any targetFramerate or in code?

limpid siren
#

yeah
unity 2021.3.11, BiRP, idk if it changes anything

limpid siren
midnight hazel
#

I'm refactoring my code to use IDragHandler instead of OnMouseDrag and am running into problems.
old code : https://hastebin.skyra.pw/zoterepojo.csharp
new code : https://hastebin.skyra.pw/izovuwesed.csharp
The old code works just fine with some minor bugs in clicks with the ui going through. The new code I cannot even get to show debug logs. I have a Mesh collider on the object I want to drag. I have a physics2d raycaster on the camera. I also have an event system setup. Could you please take a look and give me a resource to look at to get Idraghandler to work? <reposting for visibility>

rigid island
#

Mesh Collider is a 3D collider

#

it uses Meshes

midnight hazel
rigid island
#

did your mesh collider actually have a mesh ? cause that already sounds wrong

#

if its 2d why did you put mesh collider

limpid siren
midnight hazel
rigid island
#

does ur mesh collider actually have a mesh in the slot?

rigid island
limpid siren
rigid island
#

like maybe some setting your got in your NVIDIA/AMD Panel ?

limpid siren
#

oh boy

#

let's see

rigid island
#

oh lawd...I just thought of something

limpid siren
rigid island
#

Can you check the Game View , click the Apsect Ratio resolution

limpid siren
rigid island
#

forgot unity put a setting there too

#

double check it

steady bobcat
limpid siren
rigid island
#

oh okay then

#

I might still suspect your GPU then

#

did you try another game or something to see if thats capped?

limpid siren
#

But I'll read the article

steady bobcat
limpid siren
#

this is very strange

rigid island
#

or you have something like GSync on or something

limpid siren
#

what is gsync?

rigid island
#

oh its nvidia specific. Syncs Gsync monitors to Gsync compatible cards to basically do what VSync does but with less input lag

limpid siren
#

ah I see

heady iris
#

variable-rate synchronization, in essence

radiant marten
#

Isn't the point of using Path.Combine() is that it uses the OS appropriate slashes?

      string path = Path.Combine(Application.persistentDataPath, "UserContent");
      path = Path.Combine(path, "TextFiles");
      DirectoryInfo dir = Directory.CreateDirectory(path);```
Is it supposed to use conflicting slashes like this? I'm currently using unity 6.0000.0.31f1
> Creating Directory: C:/Users/phili/AppData/LocalLow/Company/OpSys\UserContent\TextFiles
> UnityEngine.Debug:Log (object)
steady bobcat
#

it wont change existing seperators in the path

naive swallow
limpid siren
radiant marten
steady bobcat
rigid island
steady bobcat
limpid siren
radiant marten
naive swallow
steady bobcat
limpid siren
steady bobcat
limpid siren
#

I'll try the empty scene

steady bobcat
heady iris
#

in my HDRP game, I control VSync entirely by setting QualitySettings.vSyncCount

rigid island
limpid siren
limpid siren
rigid island
# limpid siren logging?
void Start(){
Debug.Log($"vsync count: {QualitySettings.vSyncCount} fps target {Application.targetFrameRate}");
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = -1;
Debug.Log($"vsync count: {QualitySettings.vSyncCount} fps target {Application.targetFrameRate}");
}```
steady bobcat
steady bobcat
#

could also just be your pc is suffering already it cant run unity or your build well πŸ˜†

limpid siren
#

I'd be surprised, especially for GPU stuff
my CPU is kinda eh, but I have a 3060, so it's surprising that I'd have rendering issues on something like that

heady iris
#

notably, i would also try putting a bunch of crap in the scene so that it takes longer to render

placid edge
#

Hello :)
I'm trying to find all child objects inside a hierarchy of child objects whose name starts with a certain string, how would I go about doing this? I already have the gist of it but i cant for the life of me find something akin to Contains or StartsWith that would help me here

foreach (GameObject button in encounterButtons.transform.Find("Scroll Rect/Mask/Grid/")+ something)

heady iris
#

You'd want to recursively walk the transform hierarchy.

steady bobcat
heady iris
#

and, yes, this sounds like a bad idea

#

what're you trying to achieve?

#

not "find objects with a certain name"

placid edge
#

im trying to find all these objects and destroy them, I knooow that i can find by tag, but i figured this would take less time as im not searching the entire scene when i know exactly where all these objects would be

steady bobcat
# placid edge they all have buttons?

The lovely ideal way would be that you have a list (serialized or made at runtime) of these objects somewhere so you can use that to destroy them later. Tags and names are not reliable.

heady iris
#

If you created all of these objects via a script, you should hang on to them in a list

#

I do that all over the place in my UI code

placid edge
#

that is true, they are being created in another forloop

rigid island
#

var button = Instantiate(etc.
myButtons.Add(button)

placid edge
#

ok ill do that, thanks guys

steady bobcat
#

tags and names bad 😠

rigid island
#

seriously what is this Javascript?

#

all these strings..

latent latch
#
Transform content = dropdownList.transform.Find("Viewport/Content");

UGUI has forced my hand

#

disgusting

heady iris
#

what are you trying to accomplish here

latent latch
#

The Dropdown component recreates itself everytime you select it, so to actually modify it you have to grab the newly created objects

#

the funny thing is that is actually includes references to these objects when it creates them, but it's internally protected

heady iris
#

oh yeah, it instantiates a template

latent latch
#

pain in the buttttt

analog rock
#

Any tips for what to do about this Z fighting? I added an offset to the scale and position of each instantiated game object but it just doesn't seem to take care of it all.


        for (int x = 0; x < mazeWidth; x+=mazeScale)
        {
            for (int z = 0; z < mazeDepth; z+=mazeScale)
            {
                float offset = Random.Range(-0.001f, 0.001f);
                mazeGrid[x, z] = Instantiate(cellPrefab, new Vector3(x + offset, 0 + offset, z + offset), Quaternion.identity);
                mazeGrid[x,z].transform.localScale = new Vector3(mazeScale + offset, mazeScale + offset, mazeScale + offset);
            }
        }```
latent latch
#

more offset

#

otherwise need some pixel discard method

loud heath
#

I just started using GitHub and have a question: Should I create a new repo for each new project I make? And I'm going to be using GitHub for my college projects, so should I create a new repo for each new college assignment or create one repo for the class and go from there?

rigid island
#

well tbh its preference

#

You can certainly have root folder and then subfolders for each assignment

leaden ice
rigid island
#

it will be much cleaner for sure

leaden ice
#

Although honestly, for a class, if it's only one person (you) contributing, one repo for the whole class isn't the worst idea in the universe

#

You may have to do cheeky things like different gitignores in subfolders for different projects though

loud heath
#

Alright, thank you!

latent latch
#

Make as many repos as you want

#

or until github emails you to knock it off

rigid island
#

is there an actual # limit to repos or na ?

leaden ice
#

I don't think there's a repo count limit, more a total size limit in GB?

Github's policies confuse me, so I could be wrong.

rigid island
#

ahh I even thought GB was per project, ig it makes sense if its total per account

leaden ice
#

It might be both

#

Or at least - separate limits for each.

latent latch
#

there really isn't an official limit on anything but the'll email you usually if your repo does get too big

rigid island
#

just says there is displaying limits

#

If a repository owner exceeds 100,000 repositories, some UI experiences and API functionality may be degraded. For more information, see About repositories.

latent latch
#

pretty generous tbh

rigid island
#

nom nom feed me your code

latent latch
#

yeah that too

rigid island
#

free research UnityChanThumbsUp

latent latch
#

probably feeding all our stuff to the LLMs

rigid island
#

Github copilot has entered the chat *

analog rock
# latent latch more offset

Sorry just saw this. I’ve played with the offset to the point the walls don’t even look right and there are still instances of z fighting lol. Could you elaborate on the pixel discard method?

sleek wharf
#

Hi guys, can someone please help me out? i tried editing this script from an asset i've bought to make the player able to pick up/throw object, but i can't figure out how to make me able to pick the object up, the raycast just doesn't seem to hit the object in any way. i tried some debugging and neither the part for picking up object or the part for throwing them "detect" the object. can someone please help me to figure this out? thanks

#

i also tried increasing the raycast range but it didnt work

rigid island
#

!code

tawny elkBOT
sleek wharf
#

sorry

rigid island
#

nvm saw video

sleek wharf
#

np

rigid island
sleek wharf
#

the object i want to pickup is not a hand parent, is a separate object

#

BRO THANK YOU SO MUCH

#

SO MUCH

#

I WAS USING MY MAIN CAMERA FOR THE SCRIPT THIS WHOLE TIME

#

the prefab included another camera i didnt notice

rigid island
#

ahhh nice lol

sleek wharf
#

which is the one i was actually using

#

thanks youu

#

❀️

rigid island
#

np 🫑

wraith cobalt
analog rock
wraith cobalt
trim schooner
#

An easier way would be to align the walls so they don't overlap

analog rock
wraith cobalt
# analog rock Okay, how?

Open the model up, select the face in question, hit delete?

Or, as Carwash said, design them so they fit together better.

analog rock
#

I know the geometry shouldn't overlap. I'm asking how do I do this.

trim schooner
#

Y doesn't need an offset. Only X and Z do, and the offset needs to be the thickness of the wall

#

and only then, applied on the approiate axis at spawn (not both)

#

dunno why you're changing the scale

wraith cobalt
#

Alternatively, the easiest solution would be to add a corner column that hides the seam.

trim schooner
#

and improve the look

analog rock
#

Okay thanks folks

latent latch
#

If you look into combining, you can discard intersecting geometry too that unity does provides some tools for

#

otherwise can do some tricks with stenciling/shaders but way more effort then the easiest solution and that's just don't let them z-fight

unkempt meadow
#

so mouse position in world space doesn't work in my second scene (works in first) and only when I move the camera down. The mouse keeps the y of the original camera position seems like.

What should I even look into here?

heady iris
#

how are you finding the camera? are you just grabbing Camera.main?

#

if so, is there a MainCamera-tagged object in the second scene?

unkempt meadow
#

yes and yes

#

in fact

#

it's like a mobile game kind of things with levels, so I just prefabbed everything I need accross scenes and dropped it in the second scene

#

maybe something broke there

heady iris
#

make sure that Camera.main is the object you expect it to be

#

maybe log it

unkempt meadow
#

the camera moves

#

when I press the down or up button

#

it moves

#

but when I click on the screen, it's supposed to do something there

heady iris
#

okay, but you should still check what Camera.main actually is

unkempt meadow
#

in the second scene, the click position is wrong only when I move the camera donw

heady iris
#

you can log it like this

#
Debug.Log("The camera is: " + Camera.main, Camera.main);

the second argument provides a "context"; you can click on the log entry to be taken to the object

unkempt meadow
#

oh yeah

#

btw

#

my canvas doesn't render in the game view (it's there in the scene view and enabled in inspector)

When I reload scene, it shows up

#

maybe it's related idk

unkempt meadow
#

OK I figured out the bug...I forgot to delete the default main camera in the second scene, as the other one was included in the prefabs I imported in the second scene...of course

modern creek
#

I want to make an invisible mesh to constrain 3d rigidbody dice cubes.. is there an easy way to make a cube mesh and flip the normals?

#

dice directly on the battlefield - like monopoly go

heady iris
#

you could take an existing mesh and reverse the winding order of every triangle

#

that would turn it inside-out

#

so, 1,2,3 -> 3,2,1

modern creek
#

Cool, yeah.. I don't have experience in mucking with the meshes directly but I asked a coworker and he said a cylinder with surface normals flipped is trivial so he's getting me one πŸ˜›

#

Followup - my dice are a little "floaty" and slow to roll, given the scale of the world. Can I .. make them ... work differently? I'm not exactly sure what I'm asking - maybe I want a different gravity for them?

heady iris
heady iris
modern creek
#

Yeah - unfortunately my world scale is already sorta.. set.. Any ideas?

heady iris
#

You can compensate for this by increasing gravity.

#

either by changing the Physics.gravity value, or by just adding extra force to the dice

modern creek
#

ah, extra force to the dice works easily

#

don't wanna change physics.gravity since i have some other stuff using it

heady iris
#

nominally, doubling gravity will make the dice appear to be half as large as they actually are

#

So if you want the dice to look 10 times smaller, add enough force to get 10x normal gravity

modern creek
#

ForceMode.Acceleration i assume?

#

hm... doesn't seem to be working:

        private void OnEnable()
        {
            _rigidbody.AddForce(Vector3.down * 50, ForceMode.Acceleration);
        }
heady iris
#

That's applying force for one instant

#

put that in FixedUpdate

modern creek
#

great, thanks - i assumed the forcemode.acceleration would "leave" the force on the rb

heady iris
#

no, it just affects how the vector is interpreted

leaden ice
#

nope. AddForce is a one-time thing

heady iris
#

ForceMode.Force and ForceMode.Acceleration are meant to be used continuously

#

ForceMode.Acceleration and ForceMode.VelocityChange ignore mass

modern creek
#

so what's the point of ForceMode.Impulse? or actually, I see from the docs acceleration ignores mass

#

gotcha

heady iris
#

ForceMode.Force and ForceMode.Impulse care about mass

#

and ForceMode.Impulse and ForceMode.VelocityChange are meant to be called once (like for a jump)

modern creek
#

oh this looks nice now

#

need a bit more Y velocity πŸ™‚ but they fall and settle pretty rapidly

heady iris
#

You'll now need to kick them significantly harder to make them go upwards

modern creek
#

yeah, i'm using vector3.down * 50 so..

#

also i coulda just used the "invert normals" checkbox on the cylinder mesh instead of having my 3d guy generate one that's backwards πŸ˜›

#

er

#

"convex"

#

or maybe that's different - just for optimizing calculation of colliders? i'm assuming there's some math that optimizes convex meshes versus those that have "interior exteriors"

heady iris
#

a convex shape has no holes or dents, basically

#

when you check that box, Unity generates a convex shape that wraps around the mesh

#

Convex shapes are much easier to reason about. They have a clear "inside" and "outside"

#

By definition, a convex mesh collider can't be inside-out

modern creek
#

I'm trying to calculate which of the six sides of the die are "up" but I'm getting some weird results. Anyone see any obvious errors?

        private Vector3 CalculateUpVector()
        {
            Vector3[] upVectors = new Vector3[] { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };
            Vector3 closestUp = Vector3.zero;
            // Find the smallest angle between transform.up and the list of upVectors
            float closestAngle = float.MaxValue;
            foreach (Vector3 up in upVectors)
            {
                float angle = Vector3.Angle(transform.up, up);
                if (angle < closestAngle)
                {
                    closestAngle = angle;
                    closestUp = up;
                }
            }
            return closestUp;
        }
#

this die is being identified as "back" (and should be "right" - 1, 0, 0)

#

er.. wait.. i need to be calculating each of the transforms vectors against world.up

#

not calculating each of the world vectors against the transforms "up"

sly shoal
#

im sooo tired so i'm gonna try to keep this brief.

i have a SceneHandler script which stores (among other things) a list of PassageHandlers. PassageHandler is a script which store (among other things) a PassageName and a reference to a SceneHandler.

i have a PropertyDrawer for PassageHandler to create a custom inspector GUI and it looks like this. You enter a name, a SceneHandler object, and then select one of the passage names from that SceneHandler.

my issue is that I can't change the Passage Name in the inspector panel after setting a SceneHandler. i can delete the text in the box and write my own but as soon as i exit the property field, it reverts back to the old name. if i delete the PassageHandler on the other SceneHandler, i am once again able to edit the name field.

EndChangeCheck returns true, so it realises that i've modified the fields in some way. ApplyModifiedProperties also returns true which i believe means it carried out a change to the serialized object? but...it clearly hasn't updated because the name reverts back to whatever it was before being edited.

am i missing something obvious here?

PassageHandler: https://paste.ofcode.org/PpSCG4NEFnx7SXk4yvBF59
PassageHandler PropertyDrawer: https://paste.ofcode.org/dALz8RQ2suuU3YTqVYK4HA
SceneHandler: https://paste.ofcode.org/rPwejgWS8C8e43v7uHM6QM

polar blade
#

Hi, I'm really sorry for asking a question immediately when I'm new here..

But, I wanted to make a quick audio to text project using unity sentis and the provided sentis-whisper-tiny repository assets so that it would work even when offline. I'm currently using Unity 6 and the latest version of sentis (2.1?)

I've looked at a lot of different tutorial videos, sites and other resources but they all seem to utilise an outdated version of the sentis-whisper-tiny repository which is now different for sentis 2.1

I have no idea where to start or how to make it so any resources, advice or help that could help me get started would be greatly appreciated, thank you!

rigid island
quiet marsh
#

I'm getting this error when trying to build for Linux

The type or namespace name 'Switch' does not exist in the namespace 'UnityEngine.InputSystem' (are you missing an assembly reference?)

How can I fix this? Why isn't Switch supported for Linux builds?

rugged pond
#

Hello, is 'SerializedObject target has been destroyed. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)' error critical? Cant find any info about it and it doesnt look lite it harm yet. I found out its caused by destroying object with SerializedDictionary which i got from asset store

Here is a code and problem gone if i comment 49-54 lines but this will break my damage system
https://hastebin.skyra.pw/udufufoviz.csharp

rigid island
#

maybe its a editor UI issue or something

rugged pond
rigid island
rugged pond
#

I saw few peoples adviced to reload editor but it doesnt helped. Also error only pop up when i'm killing enemy

rugged pond
rigid island
rugged pond
#

Oh, its same as on screenshot

SerializedObject target has been destroyed.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

rigid island
rugged pond
#

I see but it just copy of the header 1 to 1

rigid island
#

oh okay

#

you tried resetting the unity layout ?

rugged pond
#

I only tried to restart editor, how can i reset layout?

rigid island
#

top right corner of unity

#

though doubt it cause this seems IMGUI and not the editor ?

rugged pond
#

Switched to default one and it doesnt help

rigid island
rugged pond
#

When i'm killing enemy. I have a bunch of them but they all just inherit script i sent above and dont have any unical methods yet

rigid island
rugged pond
#

On destroy. If i deal not enough damage thru TakeDamage to call destroy then nothing happens

rugged pond
#

In case someone else will have similar problem, this line placed before Destroy(gameObject) helped

this.hideFlags = HideFlags.HideInInspector;

rigid island
#

huh hiding before destroying an object ? weird..

#

must be some weird cleanup bug in dictionary asset

#

still points to editor only issue anyway

rugged pond
#

I've tried to move it to different script and destroy before destroying entity but it still return me error, either as a disabling it with this.enabled = false

craggy veldt
#

edit-mode, right?

somber nacelle
#

unlikely that would fix it, the issue isn't how they are destroying the object, the issue is related to an asset that has editor code that doesn't appear to be properly handling the disposal of the serialized object

leaden solstice
#

That looks like an issue in whichever serializedictionary library they are using

prime lintel
#

Is it possible to alter the timescale of a single object, or pause any scripts running on it for a certain amount of time without significant refactor?

somber nacelle
#

the time scale is global, but you could always give your components some "timescale multiplier" that you use whenever you need to multiply by deltaTime

prime lintel
#

Thank you

daring cloud
#

When I build my game, unity makes a second black screen called Unity Seconday Display. Any idea why or how I can get rid of it? I only have one camera in my scene set to Display 1 and I have a few other cameras that are making render textures, but they dont have a display associated with them

steady bobcat
ocean mirage
#

Hello, i am developing an action rpg like poe/diablo and im not sure if the question is here in the right place. I have a hard time to understand how to create items the "best practices way". A phyiscal item can drop and needs to be shown on the ground and also have a little canvas where the item name shows up and by clicking on it, it gets destroyed and sends an event. After that the item should be in the inventory and i asked myself a question.
Should the item on the ground be the same item in the inventory or should i create an inventory item and destroy the physical item on the ground after looting it? Any tips would help, thank you.

latent latch
#

For Diablo-type games I'd probably try to keep it all as data as much as possible though.

#

And to answer the question of if the item that spawns on the ground is the same item you pickup, I'd say don't roll modifiers or any operations unless the player picks it up.

#

Unless you do want to show a tooltip on hover for ground items, then you probably will have to.

ocean mirage
#

Hey Mao, thank you so much for helping me.
I think there will be many item drops in the game and in generell the game needs to handle alot of items at the same time. Im having a hard time to understand how i can seperate a backend/frontend type of thing in unity, but one day ill figure it out whats a good architecture and when to use scriptable objects etc.
Yes, i will show a tooltip of an item whether its identified/not identified on the ground.

latent latch
#

The only time an item needs to become a GameObject is when there's some sort of scene presence (mesh renderer), but otherwise it can just be data. So an Item falling onto the ground should initialize as a GameObject, with the actual weapon data wrapped in it. When it's picked up though, you can remove the wrapper and store that data.

ocean mirage
#

Right now i use a hybrid model lets say. I use scriptable objects and also use class properties that gets the first data of the scriptable objects and after that i manipulate the properties with functions for each individual gameobject most of the time since everything needs to scale with level.

latent latch
#

When you use that Item, such as a weapon, the data should include a blueprint to what type of mesh it becomes and then you will initialize a GameObject once again.

ocean mirage
#

Understood, do you have maybe a reference?

latent latch
#

Unfortunately, no. Just something I've done before myself ;p

ocean mirage
#

Yeah i belive that. Most videos dont go that much in detail with complex architecture.

#

I need to think about that. Good advice, makes sense.

latent latch
#

Having some type of constructor inside of a the data object is a good idea though so you can quickly construct a GameObject from it.

#

Or some factory type system where you can feed it that data object and get a GameObject from that

ocean mirage
#

It sounds good, im not sure how to do it in unity.

#

But ill make it. Thank you sir.

sly shoal
steady bobcat
# sly shoal is anyone able to assist with this

the unity examples for property drawer don't seem to do change checks or apply changes so perhaps this is not meant to be done there?
It clearly isn't actually keeping the changed value if its lost once the drawer is destroyed.

sly shoal
#

originally the change checks and apply line wasn't there and the same thing happened

#

i dont think they affect the issue either way

hexed pecan
#

Currently you are doing 231

#

Ah that's a property drawer, yeah you shouldn't have to manually call Update and ApplyModifiedProperties when using those

sly shoal
#

yeahhh

#

like i said, im able to change the passage name just fine as long as there's no SceneHandler assigned in the Target Scene Handler field

hexed pecan
#

@sly shoal GUILayout does not work in property drawers

#

That might be causing the issues

#

You are supposed to only use the GUI versions, not GUILayout

sly shoal
#

hm interesting

hexed pecan
#

And manually manage your rects

#

(It's ass)

sly shoal
#

yeah that does sound ass

hexed pecan
#

I made a base class for my property drawers that has helpers to mitigate that

#

Like GetNextRect(ref rect)

steady bobcat
#

try using the new visual elements instead i think 2022+ supports editor gui and visual elements together right?

sly shoal
#

so i just need to replace the rect = GUILayoutUtility... with a manually defined size?

hexed pecan
#

Yes. Everything that has GUILayout has to go/be swapped

sly shoal
#

okey ill try that

#

ohh shit that means i have to remove the Popup too

#

damn.

hexed pecan
#

EditorGUI.Popup should work

#

I think i just recently did that in a property drawer

#

Wait no, I used a GenericMenu

#

Something like this on button press:cs var menu = new GenericMenu(); menu.AddItem(label, false, () => Debug.Log("TEST")); menu.ShowAsContext();
EditorGUI.Popup prob also works but you need to provide it a rect

sly shoal
sly shoal
#

ill forward my original message over

hexed geode
#

how would i get the horizontal and vertical angle to the player?
doing this doesnt seem to give a result i can describe, but it's not what i want

        Vector3 toPlayer = player.position + Vector3.up - (transform.position + Vector3.up * eyeHeight);
        toPlayer = toPlayer.normalized;

        Vector3 horizontalToPlayer = Vector3.ProjectOnPlane(toPlayer, transform.up);
        Vector3 verticalToPlayer = Vector3.ProjectOnPlane(toPlayer, transform.right);
        Debug.Log($"{horizontalToPlayer}, {verticalToPlayer}");

        float horizontalAngle = Vector3.SignedAngle(transform.forward, horizontalToPlayer, transform.up);
        float verticalAngle = Vector3.SignedAngle(transform.forward, verticalToPlayer, transform.right);

        Debug.Log($"{horizontalAngle}, {verticalAngle}");

        animator.SetFloat("LookUp", verticalAngle / 45);
        animator.SetFloat("LookRight", horizontalAngle / 45);
#

...nevermind, i messed up my x and y axes

leaden ice
#

It's also not clear to me what "horizontal" and "vertical" angles mean

heady iris
#

you're recovering a pitch angle and a yaw angle

craggy veldt
#

usually you'd use forward, up, down etc for directions

#

there's no vertical/horizontal in vector maths

heady iris
#
Vector3 flattened = Vector3.ProjectOnPlane(entity.transform.forward, Vector3.up);
yaw = Vector3.SignedAngle(Vector3.forward, flattened, Vector3.up);

Vector3 rotated = Quaternion.AngleAxis(-yaw, Vector3.up) * entity.transform.forward;
pitch = Vector3.SignedAngle(Vector3.forward, rotated, Vector3.right);
#

here's how I did that

craggy veldt
heady iris
#

what?

craggy veldt
#

ye

heady iris
#

i don't understand what you're talking about

craggy veldt
#

you use axes instead of horizontal/vertical for directions

heady iris
#

the point here is to turn a direction into a left-right and up-down angle

#

so that the animator can use those

#

I suppose you could also convert the direction into local-space and then pass in the X, Y, and Z components of that direction

#

but then you'd need to make a blend tree that can use all three of those parameters

#

importantly, the angle values are linear -- going from 10 degrees to 20 degrees means you play the "look right" animation twice as strongly

#

the response to a direction vector isn't linear

#

you turn less and less as a vector approaches, say, [1,0,0]

worn star
#

any good resources to learn how to make a node based editor window in Unity

#

like learning how to use Editor Window , and Unity GUI , pls help

#

πŸ™

rigid island
#

its pretty detailed

wintry crescent
#

I noticed I had an unneeded XR plugin in my project, so I removed it. But now, many scripts from certain packages I'm using, are reporting errors because XRSettings is missing - but they're all within an
#if ENABLE_VR
precompilation block. Why is ENABLE_VR still true after removing the package? How can I disable it?

#

I don't have anything that is VR specific in my project - simply an unrelated plugin that offers support for it

rigid island
#

I havent touched VR but isnt VR mode eneabled when you are in that build profile ?

wintry crescent
#

and that's what's causing issues

#

which build profile? issue persists on both linux and android build profiles

rigid island
#

oh okay mb never touched VR but ig its not a build profile, maybe under project settings somewhere

wintry crescent
#

also nope - there are no xr-related settings in my project settings anywhere

rigid island
#

saw this but idk seemed old ig

wintry crescent
rigid island
wintry crescent
#

I don't have XR settings in my project settings

#

only XR Plugin management, and it only has a button to install it

rigid island
#

ah okay screenshot is old then

rigid island
wintry crescent
#

I'm on unity 6 btw

rigid island
#

same place Project Settings

wintry crescent
rigid island
rigid island
wintry crescent
rigid island
#

yeah just wondering.. unless something hidden somewhere seems similiar lol

astral nexus
#

Hi, I'm starting to use Adaptive Probe Volumes in Unity 6, but I have a question about git and their data: do I need to include those .bytes files in git or just ignore them in gitignore?

rigid island
#

πŸ“ƒ Large Code Blocks

tawny elkBOT
soft shard
# worn star any good resources to learn how to make a node based editor window in Unity

I remember seeing a video on how to make a Behaviour Tree with a custom node editor, though they were using UIToolkit instead of OnGUI for building it, if your not opposed to that approach, maybe you may find it helpful: https://www.youtube.com/watch?v=nKpM98I7PeM

This video is an hour long epic into how to create behaviour trees using ui builder, graph view, and scriptable objects. UI Builder accelerates editor tool development by visual drag and drop editing. Scriptable objects are used for serialisation, and graph view is the same node graph backing used by shader graph.

Project files available here!
...

β–Ά Play video
cyan mortar
#

Oh sorry.

#

I'm trying to keep my player within a 2d level's boundaries. The issues is that I cling too hard to the edges.

hazy nymph
#

so your player is stuck in the air on the wall and doesnt fall down naturally? @cyan mortar

cyan mortar
#

Normal walls, no. Boundaries I set with the variables, yeah

#

it slides down more slowly

#

a lot more than if i didn't "push"

hazy nymph
#

maybe try doing all that stuff in FixedUpdate thats generally better for Physics calculation

hazy nymph
#

yes

rigid island
#

it shows

hazy nymph
#

ok sorry i will delete

languid hound
#

Bumping this

#

Having the same issue as them but it's very obscure so I cant find any solutions online

cyan mortar
#

My code got improved with fixedupdate, but my player kinda vibrates once i push

hazy nymph
#

is your movment (push) also in FixedUpdate?

broken igloo
#

anyone know how to fix projects not appearing in respitory?

cyan mortar
analog rock
# languid hound Bumping this

No specific advice but unity has an FPS and TPS starter assets controller, could probably solve a lot of issues by bringing one or both into your project and comparing and contrast with your own implementation

leaden ice
# broken igloo

unable to load repositories sounds like you aren't properly signed in

#

or there's some kind of connectivity issue

broken igloo
leaden ice
#

Or their servers are down

leaden ice
broken igloo
#

i am

languid hound
#

Brb

leaden ice
# broken igloo

Did you actually set up Devops and version control through the unity cloud website?

#

do you have repos?

broken igloo
#

idk what that means 😭

leaden ice
#

Then that's your problem certainly

broken igloo
#

i jst started unity lol

leaden ice
#

WHy are you trying to add a project from a repository then

#

what are you trying to do?

broken igloo
#

someones helping me start a game and he inv me to organisation

#

i joined it and its not there

leaden ice
#

You need to pick the right organization here

#

if it's not there, then you haven't been properly added to the org, or you haven't been given the right permissions

analog rock
broken igloo
hazy nymph
#

@cyan mortar Maybe set RB collistion to Continious idk normally i would say the issue is that theres Fixed Update somewhere and Update and that gets mixed up but if its both the same idk

broken igloo
leaden ice
# broken igloo

Clearly you have some kind of error happening base don that unable to load repositories thing

#

go look at the hub logs

#

Open Log Folder here

broken igloo
leaden ice
broken igloo
leaden ice
# broken igloo

yeah it really seems you're not fully logged in - the access token is expired

#

I would just restart the hub and/or log out and back in

broken igloo
hazy nymph
#

you know what you could just try this: (instead of the whole Fixed Update stuff) @cyan mortar

void Update() {
Vector3 pos = transform.position;
pos.x = Mathf.Clamp(pos.x, x1, x2);
pos.y = Mathf.Clamp(pos.y, -999, yTop);
transform.position = pos;
}

leaden ice
broken igloo
leaden ice
#

something is wrong with your account then I guess?

#

Is your unity hub up to date?

broken igloo
#

yh i jst updated it a few mins ago

cyan mortar
hazy nymph
#

i guess u have to make some colliders then

midnight sun
#

Why does SerializeReference not show the picker thing with interfaces

leaden ice
midnight sun
#

Oh my god

leaden ice
#

It would be something you write

#

anything is going to be bespoke to your particular game

safe zinc
#

Is there any way to organize some of the folders that are dropped under Assets? Like TMPro Settings and others?

#

Or XR

#

They seem to be dumped in Assets, and you can't just drag them into a sub folder

naive swallow
#

Fairly sure you can

safe zinc
#

Yea, but, TMPro would be created under assets, so if you drag it, it won't help

somber nacelle
#

what does that even mean? because you absolutely can put the tmp folder into a subfolder, i do it in every project

safe zinc
#

But if there is an update, wouldn't it recreate it under Assets?

somber nacelle
#

that is not the TMP package itself, it is the TMP Essentials, and if there is an update, much like when you update any asset, it will find the correct folder because it's most likely based on GUID from the meta files and not the actual path

safe zinc
#

Ok, thanks

somber nacelle
#

also none of that was code related

midnight hazel
#

I'm struggling with how I should code something. What I want is to have a series of cards, in which you can select a card and drag it to a new position in the series. I have the cards as a list already and could reorder them using a placeholder gameobject. What I can't think of is how to make the card move and what it should look like making a new space. any help?

latent latch
#

For dragging, Unity offers IDragHandler interfaces which helps a ton for this stuff. As for 'making space' I assume you mean the gap space between cards, and what I'd do is when you actively drag the card, make the neighboring cards in the list offset opposite of the current dragged card.

midnight hazel
#

Okay, I get idraghandler stuff. What I'm still struggling with still is how to get the card to 'know' when it is between other cards

latent latch
#

Yeah I kinda get what you mean. Thinking back, I don't think games like Slay the Spire allow you to do that

#

I guess how I would handle this is constantly raycast and when I'm over a card that I want to insert it into, I would look for the neighboring card depending on the side I've raycasted on and split them apart.

#

otherwise some comparison of *all card pivots and figure out where your dragged card is relative to that

midnight hazel
#

Thanks for the input, I'm also tring to think how a raycast would work with idraghandler, since the current card would be under the pointer. How would using a grid work with this?

latent latch
#

Just remove detection from the dragged card

#

The grid sounds like an idea too, assuming your cards dont move too much and just want to compare in those colldier areas

leaden bluff
#

Hihi~
Not 100% it's the right chat to ask this, but:
I have various ScriptableObjects (SO's from here forward) of class, lets say AnimStateFile with AnimationClips member variables, which are exposed with the classic private variable, public get/setter property. But almost everytime I change the script of AnimStateFile all these SO's lose the reference to their AnimationClip.

This also happens with multiple other types of variables/objects, where they lose their reference or reinstantiate from a default constructor.
To avoid losing permanently this information I wanted to repo the SO's so even if they changed, I could atleast have the related information backedup on the repo but... I can't find a singular line on the "yaml-ed version" of the SO's. ("yaml-ed version" = the text version of the SO you get when you drag it into a text editor)

So, the question becomes, how can I backup the SO's information completely? And what could I be doing wrong to avoid losing all the links/references/instanced objects every time I change the script of the SO's?

leaden ice
#

unless you're chjanging the names of the fields

#

or whether those fields are serialized or not

leaden bluff
#

Example of what kind of change I mean

leaden ice
#

As you said - if you want them to show up in the yaml, they need to be serialized

#

serialization is what puts them in the YAML

#

If you see them in the inspector - they are serialized

#

unless you're using a plugin like Odin or something

heady iris
#

Are you assigning data into them with an editor script?

leaden ice
#

or a custom editor

heady iris
#

Perhaps it is not correctly saving the changes, in that case

#

Particularly if you're also generating the animation clips via script

#

In that case, they can look totally fine until you quit the editor

leaden bluff
heady iris
#

..and then they die, because they didn't actually get saved persistently

leaden ice
# leaden bluff Whoopsies? yeah using odin

yeah if you're using odin and depending on the fact that Odin can show private variables in the inspector and not actually serializing them, that could be part of the problem

#

Fen also is making a good point about the clips themselves

leaden bluff
leaden bluff
heady iris
#

okay, so that rules out a bunch of really hilarious avenues

#

(ask me how i found out about all of them)

#

πŸ’₯

leaden bluff
#

... how did you found out about all of them?
Also back on track:

[HideInInspector]
protected AnimationClip animationClip;
[ShowInInspector]
[TitleGroup("Anim state")]
public AnimationClip AnimationClip
{
    get {return animationClip;}
    set {
        animationClip = value;
        if(animationClip==null){
            totalFrames=0;
            return;
        }
        
        int frames = (int) (animationClip.length * ParametersNS.GlobalParameters.FPS);
        this.SetTotalFrames(frames);
    }
}
leaden ice
#

You need [SerializeField] on the first field to serialize it

#

that will put it in the yaml

leaden bluff
#

Lemme check right away then

leaden ice
#

Odin is giving you bad Unity habits πŸ˜›

leaden bluff
#

animationClip: {fileID: 7400000, guid: 845dfcb4d2df19841837ae223cecff14, type: 2}
There we go

#

Thanks @leaden ice , @heady iris

hexed geode
#

how do i limit the change over second of a variabe
for dps caps

leaden ice
hexed geode
leaden ice
#

no this would only let you limit how much it changes per frame

#

also... 1 / dpsCap? that's not the limit you want

hexed geode
#

yeah sorry math is off

#

dpsCap * Time.deltaTime or something would be the limit i want i think

leaden ice
#

I wouldn't use Update

#

there's no reason to use update

#

you would do this in the function where you change the health

hexed geode
#
    public void DamagePlayer(float damageAmount)
    {
        float desiredHealth = currentHealth;
        if (currentHealth < damageAmount && currentHealth > 1 && Random.Range(0, 4) == 0)
        {
            desiredHealth = 1;
        }
        else
        {
            desiredHealth -= damageAmount;
        }
        DOTween.To(() => currentHealth, x => currentHealth = x, desiredHealth, 0.1f);
    }
#

this is where i change the health

#

i have no idea how i'd limit the change per second for this
this question has been plaguing my mind for weeks

cold parrot
#

you could, for example, decrement a variable each update by the allowed rate and use incoming damage to fill it up, adding the delta to the actual damage counter.

hexed geode
cold parrot
#

what I described above is how any simple rate limiter works.

#

You can skip the automatic decrement and do it only on demand but that will typically have various problems in a game as you have noticed.

hexed geode
#

the problem i have with an automatic decrement is that it'll expand the allowed change when it's not necessary

#

unsure how to explain what i mean properly

#

im not sure what im looking for is even possible or even makes sense, to be fair

#

yeah i dont think the exact thing im looking for makes any sense lmao, thank you for your help

leaden ice
#

something like that

#

No need for Update

#

(note the entries in the queue must contain the time and the amount the health changed by. You can use a SortedList for this to make things efficient)

hexed geode
lucid brook
#

Is there a way to write this cleaner or more compact?

if (playerMovement.moveSpeedMultiplier == 1f)     PlayMotion(FootStepMotion(walkingHeadBob));
else if (playerMovement.moveSpeedMultiplier < 1f) PlayMotion(FootStepMotion(crouchingHeadBob));
else if (playerMovement.moveSpeedMultiplier > 1f) PlayMotion(FootStepMotion(sprintingHeadBob));
leaden ice
#

something like this?

#

you could use a pattern-matching switch statement too

#

your third else if can just be an else

lucid brook
lucid brook
lucid brook
#

Thanks!

wheat spruce
#

public void Damage(float value) => CurrentHP = Mathf.Max(CurrentHP - value, 0f) this is similar to my own damage method

#

@hexed geode

#

You could do

public void Damage(float value) => health -= (CanHurt ? value : 0f) * deltatime;

#

We can go deeper! stonks
public void Damage(float value) => health = Mathf.Max(1f, health -= (CanHurt ? value : 0f) * deltatime);

#

Okay I'm done 🀣
public void Damage(float value) => health = Mathf.Max(1f, health -= (RandomRange(0,4) == 0 ? value : 0f) * deltatime); untested, would be funny if it actually works

rose willow
#

how do I get the first digit of a int?

somber nacelle
#

can you explain the purpose of this before an answer is suggested? because that could drastically change the answer

rose willow
somber nacelle
wheat spruce
#

As in, 379 to 179? For clarification

rose willow
# leaden ice to do what with?

I have a health int and I want to get the first digit of it and then set a different var to be equal to the first digit of the health int

rose willow
wheat spruce
rose willow
somber nacelle
#

again, for what purpose

leaden ice
#

What's the end goal?

rose willow
leaden ice
#

one option is simply to format it to a string and loop over the characters

#
string numberString = myNumber.ToString();
foreach (char c in numberString) {
  Debug.Log(c);
}```
somber nacelle
#

you can also do something like this:

int myNumber = whatever;
while(myNumber < 0)
{
  var character = myNumber % 10;
  myNumber /= 10;
}
#

of course if you want specific characters from the int praetor's would be more versatile. my suggestion gets all of them (technically in reverse order)

rose willow
#

ill try to implement your ideas, ill be back!

#

thanks for the help!

lost lotus
#

What is the best tree data structure for rendering purposes? I have a dungeon and I want to implement a render pass feature that makes it so only the currently active room and adjacent rooms are rendered. I figure I should create a tree data structure that describes rooms and their neighbour. Whats the best way to implement this so its performant?

leaden ice
#

but yeah, pretty simple to do with a graph

#

You literally just need to iterate over the neighbors of the single node you're currently looking at

#

Technically it's a BFS with a depth limit of 1

lost lotus
#

alright thank you

heady iris
#

correct

#

The only annoying thing is that you need to maintain the links in both directions

#

If you're building the dungeon dynamically, then you just make both connections at the same time

#

If you're manually punching in the connections in the inspector, then it's more of a nuisance

lost lotus
#

thats true

rose willow
somber nacelle
#

#πŸŽ₯┃cinemachine
but also if you want a cinemachine camera to update while it is not live then use the Priority to determine which camera is live rather than disabling them. that will allow it to go into standby which you can control the update frequency of using the standby update property

wind blade
#

aha I did not see there was a cinemachine channel, thank you. Should I repost in there or link to this post or what

somber nacelle
#

you would repost it there and delete the original. but you'll get the same answer i just gave, don't disable the cinemachine camera components and instead let them go into standby so that they can update while not live

wind blade
#

well, that is what I am doing πŸ€”

#

so I will carry on the convo over there

prime lintel
#

Do IEnumerator methods re-enter the function at the very beginning or do they re-enter in the loop they left?

For example if I had a loop that loops through indexes of an array, that only stops when the idx value reaches array.length - 1. Will the method re-enter at the beginning of the loop or at the beginning of the function where I initialised the idx value to 0?

leaden ice
prime lintel
#

Okay thank you

west lotus
kind willow
#

I can rotate a thing along 2 axes by using an empty gameojbect and rotating 2 things separately
Can I achive the same result without an empty, reasonably? It's not that bad if you want just 2 rotations tho, but I wanted more and ended up in a nested hell

spring basin
#

Hello, is there a dedicated channel for text mesh pro?

latent latch
#

Depends if it's something to do with the UGUI, or the actual API

spring basin
#

its about devanagari fonts

#

there's this asset

#

but im worried the plugin might not work, since the developer website is down

latent latch
spring basin
#

so figured i try implement it

#

okay ty πŸ˜„

eager fulcrum
mellow sigil
#

It refers to WorldGenerator.OreGenerationJob so constructors and fields in that class

eager fulcrum
#

ah didn't notice that, thanks

safe ore
#

I thought it might be because of the Z axis but I tried clamping it and it still happens

leaden ice
safe ore
#

ah my bad, its a ping system and its meant to clamp the ping to the side of the screen but when I turn around the ping appears opposite of where I placed it down.

#

when i'm not clamping it, if the z < 0 I hide the object

#

that works fine, but now that I don't want to hide the object I get this weird effect

kind willow
#

I am sure that I have encountered this problem and I fixed it by, well

#

hiding the object by assigning it crazy coordinates

safe ore
kind willow
#

I remember I just downloaded someone's assets to make UI markers on objects but on main canvas

#

and I saw this happening so...

safe ore
#

this was my fix before

#

but this doesn't have it so the marker clamps to the side of the screen

#

I just hide it when the z is < 0

steady bobcat
#

what do you get if you do world to viewport pos first?

kind willow
#

it is done first?

steady bobcat
#

im wondering if the z for viewport pos will be less than 0

safe ore
#

viewport doesn't work

#

it sticks it at the bottom left of the screen

#

thats why I use WorldToScreenPoint

steady bobcat
#

i presume its due to the projection causing anything "behind" to not behave

safe ore
#

quite possibly

kind willow
steady bobcat
safe ore
#

I want flexibility, the option to have it hide or the option to have it stick onto the side of your screen, so it could even double as a hit marker thing to show you where you've been hit from.

steady bobcat
#

In my mind im thinking if you can get a viewport normalised dir to the world pos then it would be usable πŸ€”

heady iris
#

let me go find that code

#

You want to use a combination of two different techniques

kind willow
#

and I did almost that too

heady iris
#
  • On screen, convert to screen-space coordinates and position the dot there
  • Off screen, find the direction between yourself and the position, then put a dot on the edge of the screen
#

with a blend between the two techniques as you get close to the edge

kind willow
#

...and I don't think I did it this way, I gonna try dig some code

#

I had 2 kinds of markers, one you described

#

and the second one which is simple af getting hidden if z < 0

heady iris
#

oops, this should really take the camera FOV into account, shouldn't it

kind willow
#

oh that's math

#

I did that without complex math I think

safe ore
#

I think I might be onto something here

kind willow
#

float angle = Mathf.Atan2(screenLocationUI.y, screenLocationUI.x); float slope = Mathf.Tan(angle);

I found this in the code

#

turns out I was using math

heady iris
#

doesn't this simplify to screenLocationUI.y / screenLocationUI.x

#

well, not quite, since it's ATan2

kind willow
#

I am not very bright and I struggle every time I need to do something and then it's done after watching guides I completely forgot what I just did

#

if it's something complex

safe ore
#

It seems to fly down to the bottom but its better than what it was

#
if (pingsScreenPos.z < 0)
            {
                // Clamp the screen position to be within the screen bounds with a buffer
                float clampedX = Mathf.Clamp(pingsScreenPos.x, pingClampDistance, Screen.width - pingClampDistance);
                float clampedY = Mathf.Clamp(pingsScreenPos.y, pingClampDistance, Screen.height - pingClampDistance);

                pingsScreenPos.z = Mathf.Clamp(pingsScreenPos.z, 0, pingsScreenPos.z);

                rectTransform.position = new Vector3(-clampedX, -clampedY, -pingsScreenPos.z);
            }
            else
            {
                // Clamp the screen position to be within the screen bounds with a buffer
                float clampedX = Mathf.Clamp(pingsScreenPos.x, pingClampDistance, Screen.width - pingClampDistance);
                float clampedY = Mathf.Clamp(pingsScreenPos.y, pingClampDistance, Screen.height - pingClampDistance);

                pingsScreenPos.z = Mathf.Clamp(pingsScreenPos.z, 0, pingsScreenPos.z);

                rectTransform.position = new Vector3(clampedX, clampedY, pingsScreenPos.z);
            }```
kind willow
#

..also I was merging my code with a code of other dude I downloaded

#

damegev

safe ore
#

lol

kind willow
#

sounds like being stoopid

kind willow
#

this is just a snippet of main method

#

I was doing this code like.. a year ago

#

and I struggling to grasp

#

I got a support for different fovs and different resolutions

#

and for markers which getting hidden out of sceen and markers which are sticking to edges

#

and it works I swear but I don't know why

heady iris
heady iris
fluid cloak
#

Hey, this is going to sound like SUCH a stupid question, but how can I check for caps lock?

#

I have tried every method I've seen online.

#

They all return false ALL the time

heady iris
#

So I had to decide:

  • How to detect when I'm in this situation
  • How to correctly calculate a position in this situation
#

I went through a few different ideas (like just trying to move the calculated screen point back onto the screne)

kind willow
heady iris
#

Unity is actually a pretty good way to do that

#

you can use Debug.DrawLine and Debug.DrawRay to visualize vectors, and use the methods on Vector3 and Quaternion to manipulate vectors

kind willow
#

I was doing that

#

I hate doing that

#

it's such a slog

leaden ice
#

At some level programming and especially game dev is going to appeal to people who enjoy math and spatial reasoning problems

#

It's not for everyone

kind willow
#

as a backstory I fell out of physics math class because turned out I liked this stuff only while I was easily grasping it

#

It's a slog and it's not fun to learn that, what can I say

leaden ice
#

Maybe you just didn't have a good teacher

kind willow
#

...here I can't disagree

leaden ice
#

Did they teach everything from books or did they use visual and hands on demonstrations?

#

People have different learning styles and maybe they didn't use yours

heady iris
#

I was never a "math whiz"

#

I was pretty good at it, but I never had a great relationship with the subject

#

I've finally built up a good understanding (especially with linear algebra)

#

thanks vrchat

latent latch
#

trig would been more interesting if it was based around 3D engines that's for sure

leaden ice
#

I was definitely a math whiz right up until calculus 3 and it stopped being easy so I also stopped enjoying it πŸ˜‚

heady iris
#

i took a computer vision class in 2015 in college

kind willow
#

I have no clue what is calculus 3 but it's my story

heady iris
#

that was the only D I've ever received

#

i did NOT understand linear algebra at the time

kind willow
#

was a whiz, stopped enjoying right when faced a wall I having to slog through

#

turns out to be able to put effort you should either love the subject or hate yourself be really determined about you needing this knowledge

heady iris
#

i learned linear algebra properly to make complicated VRChat shaders

steep herald
#

I'm trying to use RenderMeshInstanced to render a trail. The max amount of matrices I can send over to the GPU at once is 1023. My trails can require several batches. I need an instanceId in the shader that relates to the total instances count. Problem is instanceId relates to the batch with the API. This means I need to let the shader know what the batch started at so I can add that to the instance ID. Setting the startIndex like below does not work because the process is not sequential and it'll just end up using the startIndex of the last batch for all batches.

Any recommendations?

for (var i = 0; i < batchesCount; i++)
{
    var batchStartIndex = i * MaxBatchSize;
    var batchSize = Mathf.Min(matrices.Count - batchStartIndex, MaxBatchSize);
    material.SetInt(BatchStartIndexProp, batchStartIndex);
    Graphics.RenderMeshInstanced(renderParams, mesh, 0, matrices, batchSize, batchStartIndex);
}```
heady iris
steep herald
safe ore
#

@kind willow @heady iris @leaden ice
This is an update to where I am, its still got jank but its getting there lol

kind willow
#

and sin/cos functions and stuff?

#

funny circle graphs?

#

seeing calculus 3 is very confusing for me because I am from another educational system where it says nothing

#

I guess I was talking about something way before that

#

I think I fell out at mere pre calculus

#

at some point at life I would have to investigate the real math but I have no idea in which form it can be done other than going to university

heady iris
#

sin/cos/etc. is all triginometry, which generally comes before calculus

heady iris
heady iris
kind willow
heady iris
#

I wonder if you could use RenderMeshIndirect

steep herald
#

I can't. We ship for mass market and it requires compute shaders support

heady iris
#

This requires compute--

#

yeah

#

and thus we get into the realm of Funny Ideas

#

I wonder if you can stuff the identifier into the object-to-world matrix

#

this sounds really evil

steep herald
#

yeah, maybe. Would require the CPU to loop over all matrices but its definitely the lesser of the 2 evils

kind willow
#

why is it often about choosing the least wrong solution notlikethis

heady iris
#

realtime graphics rendering is fun

#

I would lean towards just including an index in the instance data

#

especially if you already have one or two other floats in there

#

(doesn't it usually wind up being 16-byte-aligned anyway?)

#

i'm a bit of a novice in this area

steep herald
#

don't ask me, so am I

heady iris
#

I might be thinking of compute buffers here

heady iris
steep herald
#

I think I can just bake it into the last value of the matrix

heady iris
#

especially since it probably only matters if you're constrained by bandwidth

steep herald
#

last column is xyz and empty I think

heady iris
#

yeah, the last column's first three components are the translation

#

The fourth one is 1 in an identity matrix (duh). I forget if it varies in other situations

#

something something, homogeneous coordinates

steep herald
#

yeah, its prob used so that you can just ship the last column when converting to homogenous coordinates

heady iris
steep herald
#

but I can overwrite that in the frag shader

heady iris
#

I was implementing inverse-square light attenuation and only had the world-to-light matrix

#

i realized I could just use the inverse of its X-axis scale to turn a light-space distance into a world-space distance

heady iris
#

you can compute multiple rotations around specific axes, then combine them

#

it takes an angle (in degrees) and an axis

#

q1 * q2 applies q1, then q2

#

q1 * v1 rotates the vector with the quaternion

kind willow
heady iris
#

I've definitely just used empties more than a few times before

kind willow
#

wait...

#

yeah I think I got why I was getting not what I was expecting

#

or not but I realzied how to do what I need

heady iris
#

there's also Quaternion.Euler if you're combining rotations around the cardinal axes (and you want to apply them in the ZXY order, in particular)

#
Quaternion.Euler(pitch, yaw, 0);

notably, this produces the correct rotation for a first person view

#

it first tilts the camera up and down, then spins it around the Y axis

kind willow
#

Quaternion newRot2 = Quaternion.Euler(-10, 0, 0); Quaternion newRot = Quaternion.AngleAxis(Time.unscaledTime * spinSpeed, Vector3.up);
that's what I was doing to achieve a slightly tilted thing spinning

#

I was multiplying them and setting as rotation

heady iris
#

hang on a second. my first person controller does this.

Quaternion turnRot = Quaternion.AngleAxis(yaw, Vector3.up);
Quaternion lookRot = turnRot * Quaternion.AngleAxis(pitch, Vector3.right);

that seems backwards...

kind willow
#

anyway I realized that I just needed to remove newRot2 and use tilted vector instead of up

#

for my case

#

but generally I still don't get how to combine 2 rotations

#

in a way it looks like having an empty and 2 independent spins

latent latch
#

eulers a poop

heady iris
#

hm, this makes a bit more sense now

#

so this also works correctly

#
Quaternion turnRot = Quaternion.AngleAxis(yaw, Vector3.up);
Quaternion lookRot = Quaternion.AngleAxis(pitch, turnRot * Vector3.right) * turnRot;
#

That more closely matches how I imagine this working

#

using a fixed Vector3.right means that we're rotating around the wrong axis

#

so the camera tilts to the left and right when we're looking along the +X axis

#

ah!

#

Rotating by the product lhs * rhs is the same as applying the two rotations in sequence: lhs first and then rhs, relative to the reference frame resulting from lhs rotation

#

The last bit is crucial here

#

relative to the reference frame resulting from lhs rotation

leaden ice
heady iris
#

so a rotation around Vector3.right is always correct

heady iris
#

lhs and rhs are the two arguments to the * operator

latent latch
#

quaternion multiplication is non-commutative

#

so there's some ordering to how you want to multiply everything out

heady iris
#

I didn't realize why it was non-commutative until reading that

#

that makes a lot more sense now

kind willow
latent latch
#

Unity does Eulers by ZXY rotations too btw

heady iris
#

Although, I'm now unsure how I'd reliably rotate an object around a specific world axis

#

I guess you'd put it on the left hand side

latent latch
#

Basically, stick to one quaternion rotation and don't diverge from it

wheat spruce
#

What is a sensible way to go about upgradable properties, like this attack example

int attackLvl;    // attack value upgrade
float baseAttack; // base value for attack
float powAttack;  // Pow is raised by this

float attackAmount => baseAttack * Mathf.Pow(1 + powAttack, attackLvl - 1);
// the final value used to deal damage
```I'll need the 4 properties to find the final amount, but if I went with that approach, I'm going to end up with a giant wall of properties thats only ever going to increase in size as I add new properties
midnight hazel
#

What type of data structure should I use if I'm pairing off units to fight one another in a card game? Multiple defenders can block one attacker, so dictionary is out.

latent latch
#

Unless you're crazy like me who has tried a full parsing system of equations

heady iris
#

it doesn't have to be expression-bodied

kind willow
wheat spruce
#
public float attackAmount
{
  get
  {
    int attackLvl;
    float baseAttack;
    float powAttack;

    return baseAttack * Mathf.Pow(1 + powAttack, attackLvl - 1);
  }
}```like this?
kind willow
heady iris
kind willow
wheat spruce
heady iris
#

If the calculations start getting too expensive, you can lazily recalculate the value only when needed

#

you'd need to set a "dirty" flag when changing any of the inputs

latent latch
#

Yeah, I like to cache my stuff out when changing equipment, but when it comes to your attack vs enemy defense, that's something you need to calculate right then

kind willow
#

I wonder how bad am I never bothering to cash anything unless it's being done every frame

latent latch
#

probably doesn't matter too much unless you're making some diablo-type game where there are hundreds of modifiers

wheat spruce
#

also with the actual way the value grows as it upgrades, that expression works, though its pretty difficult to judge how it actually changes over time. The best thing I've come up with is to put the same thing into a spreadsheet

kind willow
#

I would just slap an animationcurve ngl

wheat spruce
#

not a bad idea, plus that enforces actual limits to be set for min/max

#

as in if there's a max of 20 levels for damage, that lets the curve time be evaluated correctly

latent latch
#

animation curve is bff

spiral ibex
#

What's the general advice on creating health bars in large(ish) quantities in world space? Let's say 100. Do people just do world space canvas? Some sprite renderers? Maybe a custom shader and instancing for optimization?

kind willow
#

I just place them on main canvas

wheat spruce
#

my enemies have a world space canvas that contains a slider

kind willow
#

this feels like the most straightforward but worst performance wise solution

wheat spruce
#

maybe, but until performance becomes a problem its not really an issue

spiral ibex
#

Do you happen to have just a handful of enemies at a time?

kind willow
random oak
# spiral ibex What's the general advice on creating health bars in large(ish) quantities in wo...

https://www.youtube.com/watch?v=cUQVLgohAjY
has good tips on optimizing this use case

Learn how to make Health Bars that stay above the heads of units in World Space!
A common need in games is to show Health Bars over some enemy or unit. In this tutorial we'll take a look at one way to achieve that in a way that enables us to retain the benefits of sliced and filled Sprites.

I also discuss some of the "gotchas" that you may enc...

β–Ά Play video
spiral ibex
#

That's more than I assumed, good to know I can be a bit lazy.

latent latch
#

canvas healthbars is a meme

#

instanced quads and textures

steep herald
kind willow
wheat spruce
latent latch
#
#

Probably the best solution assuming you've hundreds

#

otherwise I think vertex coloring is fine too with srp batcher

kind willow
#

I read that too

#

despite never having more than 30 enemies

wheat spruce
#

I'd just give the enemy a quad and change the width as it loses health

#

and if the enemies will even have health bars in the actual final game, I couldnt say

kind willow
#

I have to say that I never did profiling

wheat spruce
#

does a vampire survivors like really need enemy health bars?

kind willow
#

but having alot of canvases is clearly worse than calculation positions and sizes for one canvas, right?

spiral ibex
latent latch
#

canvas is just bad cause each one is a single drawcall

#

like this solution was the best for built-in and probably still the best for URP lol

kind willow
#

I can't say I played many games

#

I think world space canvas is only good for like

#

Doom 3 alike monitors

#

I don't remember something like that in other games

#

where it's a UI interface of a computer you can interact with like it was a computer

#

it got it own UI buttons and mouse cursor

#

yeah I haven't play much games, it should be in many games probably but I don't recall

dim hedge
#
        {
            try
            {
                var relationship = await FriendsService.Instance.AddFriendAsync(playerId);
                Debug.Log($"Friend request sent to {playerId}.");
                return relationship.Type == RelationshipType.FriendRequest;
            }
            catch (FriendsServiceException e)
            {
                Debug.Log($"Failed to Request {playerId} - {e.Message} - {e.ErrorCode}");
                return false;
            }
        }``` it returns true even if playerId is not correct. it also lists the not existing friend at FriendsService.Instance.OutgoingFriendRequests
#

any idea how to check, documentation doenst handle this

#

If I delete an account that has friends, these links are not removed either.

kind willow
#

``
Quaternion lookRot = Quaternion.AngleAxis(Time.unscaledTime * spinSpeed, new Vector3(0.1f, 1, 0));

float pitch = 10;
Quaternion turnRot = Quaternion.AngleAxis(Time.unscaledTime * spinSpeed, Vector3.up);
Quaternion lookRot = Quaternion.AngleAxis(pitch, turnRot * Vector3.right) * turnRot;
``
same things

#

slightly different tiltness I guess but it's not what I care about

sterile reef
#

what re you trying to do @kind willow

#

turning like a ship?

kind willow
#

turning like a

#

you know those sticks on top of campfire

#

permanently tilted along one axis, spinning along another

#

and I don't want to make an empty

sterile reef
#

you mean like... s skewer?

#

roasting pig

#

type of rotation

kind willow
#

I guess

#

thing is by default the gameobject looks straight up

sterile reef
#

i mean you can rotate the Global rotation of the object Along X and Z and use the local rotation of Y to spin it right. maybe that works

kind willow
#

I am not getting it

heady iris
#

so, transform.rotation *= ...

kind willow
#

that's eh

#

yeah I figured it would be about doing transform.rotate or modifying transform

heady iris
#

use some small value (based on Time.deltaTime) if you're summing up these rotations over time

kind willow
#

but I want to rotate several objects in sync and not all of them are spawned right away

heady iris
#

You can also use Transform.Rotate, yes

heady iris
kind willow
#

so I think I want to be overriding rotation

heady iris
#

At that point, using an empty makes a lot of sense.

#

You already need to remember an original rotation that you apply a modification to

kind willow
#

why would I need to rememebr original rotation

#

they all spawn having zero

#

I mean identity or whatever

#

the task looks so simple

#

I guess I can rotate an abstract Quaternion

#

not actual transform

wheat spruce
# wheat spruce also with the actual way the value grows as it upgrades, that expression works, ...

It's not too bad doing it this way

public float MagicResult
{
  get
  {
    // the base value to scale the result by
    float baseValue = MagicBase;

    // the current level of the property
    int currentLevel = MagicLevel;

    // the min and max level that this property can be between
    Vector2Int levelRange = MagicLevelRange;

    // the curve that is used to evaluate, allows for different types of growth to be achieved
    AnimationCurve curve = LinearCurve;
    
    // the evaluation time for the curve as a [unit]
    float eTime = NormaliseValue(currentLevel, levelRange); // Mathf.InverseLerp(minLvl, maxLvl, curLvl) 
    Debug.Log($"eval: {eTime.ToString("F3")}");

    // the curve value that has been evaluated
    float cValue = curve.Evaluate(eTime);
    Debug.Log($"cValue: {cValue.ToString("F3")}");

    return cValue * baseValue;
  }
}```
#

I'll shrink its size down once I actually start using it, most of it is redundant

kind willow
#

I always shove lerps onto animationcurves every time I can

wheat spruce
#

public float MagicResult(AnimationCurve curve) => curve.Evaluate(NormaliseValue(MagicLevel, MagicLevelRange)) * MagicBase; actually, its really only a single lines worth of code πŸ˜…

wheat spruce
#

I use it to check how fast the vehicle moves in relation to its top speed
Mathf.InverseLerp(0f, VehicleObject.TopSpeed, Mathf.Abs(CurrentSpeed))
That way once this has a value of 1, I dont have to apply anymore force to it

stark plaza
#

are autoproperties like this

[field: SerializeField]
public int Age { get; set; }

the best approach for fields that could need custom get; set implementation?

leaden ice
kind willow
#

damn how do I format it to be in one beautiful black square?

leaden ice
#

```cs
code
```

stark plaza
kind willow
#

as far as I know autoproperty is only {get;set;}

#

why do you have sarializeField on top of a property?

#

you should have it on top of _age I think

#

since Age is basically a method

#

not storing stuff on itself

stark plaza
#

I see

#

Is just that my code ""headers"" is so messy I wanted a way to make it simpler

kind willow
#

is Quaternion.Euler (1,1,1) the same thing as transform.rotation of a gameobjects having 1,1,1 angles?

stark plaza
kind willow
#

personally I don't get why would you want alot of properties

#

I only use them when I need some real logic behind it

#

they create so much clutter

meager apex
#

Can you suggest videos or resources on solving Unity errors when migrating a project to another Unity version?
migrating to one of the LTS version throws errors which takes a lot of time sometimes. tell me the best practices and what should i do and dont's?

stark plaza
#

that creates clutter too

kind willow
#

you can't I guess

#

I just don't mind having some things public

#

even if it's alot of things

stark plaza
#

I'm so afraid of leaving stuff public lmao

kind willow
#

IDE can show you all references in two clicks

stark plaza
#

true

kind willow
#

I would only get it if you are working in a studio having more than like 3 programmers

wheat spruce
#

its a very basic force calculation

kind willow
#

wait it just applies force till it reach the top speed

wheat spruce
#

yeah

#

it works quite nicely

kind willow
#

that would rubberband if friction

#

I guess not very much

wheat spruce
#

let me double check if it ends up making the speed oscilate once its at the top, becuase it might go 1, 0.9999, 1, 0.9999, 1, 0.9999 each frame

kind willow
#

anyway that would always overshoot max speed and I can't stand it

#

it's clearly acceptable in a context of a game tho

wheat spruce
#

ah yes

kind willow
#

oh also

#

I remember

#

I used code I stated because I had crazy acceleration and low max speed

#

aka your fps character

#

it never overshoots

#

but I wonder how suboptimal it is

wheat spruce
#

I'll put a TODO to try and fix it later on, I cant see it being much of a problem

kind willow
#

on a vehicle it's not, on a character, it's at very least a jittering camera

#

thing is

oblique spoke
#

@mossy scaffold Don't crosspost

kind willow
#

nice mod avatar

#

I saw most implementations limiting velocity or applying backward force

#

but I don't get why if you can calculate exact force to not overshoot the limit

#

I guess if you won't go for overshooting that would make friction kinda more powerful?

#

since this calculation not accounting for drag or friction

#

anyway if someone share code how to achive this rotation
https://openusd.org/images/tut_xforms_spin_tilted.gif
by having a quaternion I can assign to different gameObjects I would very appreciate that
I am done breaking my brain over this seemingly simple problem for today

#

...wait the gif is from the site which describe how to code such rotation
AND it also shows how to do it wrong showcasing the wrong result (I got exactly that)

#

too bad it's not for Unity

leaden ice
kind willow
#

that's it!
to my shame I ve wasted like an hour on that and it's not working

leaden ice
#

As long as you have the correct axis vector

kind willow
#

I did try that and it didn't work

leaden ice
#

Then you had the incorrect axis vector

#

or you applied the rotation incorrectly

kind willow
#

I know that I made a mistake somewhere

#

this is what I was always getting

dim hedge
lost lotus
sterile reef
keen ridge
#

What's best practice for using a physics based character while also using root motion?

It seems just using root motion allows the character to pass through other colliders. Using OnAnimationMove combined with RigidBody.MovePosition also allows the character to move through other colliders.

Is best practice to apply forces and/or set velocities?

lean sail
hexed pecan
#

I never tried root motion but not sure how it is even supposed to be compatible with any physics

fallow quartz
#

Someone here has used git-filter-repo in here?

dense pasture
#

there any way to limit an integer field value between min/max without it showing a slider? i see a min but not a max

keen ridge
#

The issue is that there are some things that you want to use root motion. Imagine a shambling zombie that doesn't walk at a constant speed. Ideally, your animation is driving the motion on that... but it seems using root motion allows it to move through walls. Using OnAnimatorMove and applying the position deltas from the animation via rb.MovePosition also allows it to move through other colliders it seems.

leaden ice
#

but it seems like your rotation axis doesn't align with that.

dim hedge
abstract mesa
#

Have a strange issue with GameCenter on my iOS device. I'm sending achievement info to it. It seems to update just fine most of the time, but when an achievement takes a certain number of something before it unlocks (example, 10,000 damage) it seems to show itself as locked in the game center even if I seem to be sending it that we're at 2% (Example, 211/10,000 dmg done)
Has anyone worked with GameCenter before and had a similar issue?

abstract mesa
#

Will move the question there

sterile reef
brazen jasper
#

how should I approach face culling? I want to generate voxel terrain, and faces that aren't visible should not be rendered. Should I change things in object's mesh filter?

young moon
#

Hello, I have a question about grids. I'm making a game with the same concept of a grid like Prison Architect or Rimworld. Currently while I instantiate each grid cell, I populate an array of GameObjects, and also of ObjectTypes using enums for "empty" cells where a player can place objects on top of. I also give each cell I instantiate a script that keeps its coordinates for when the player tries to click it, here using Raycast and a collider. Now this works great and I have also made placing and removing of objects (for example a bed) on top of this grid, using the enums.
My issue here is when I think about saving objects for when the player wants to load their game. Is my way of doing grid poor for this? I'm not exactly sure what would be the best way to handle saving. Would it be giving the placeable objects some kind of script with ID for type and the coordinates for prefab instantiating which I save in one big JSON file, then use that and populate my ObjectType on load? If I use this idea, I'm a bit unsure how to handle the grabbing of the scripts since it'll be many. I guess I can, "populate an array it goes through" when you save. Or is there a better way to do all of this?

rigid island
sterile reef
safe ore
young moon
# sterile reef every cell you have has a Monobehaviour on it?

It doesn't inherit from Monobehaviour. But another comment made me realise in general that I shouldn't do cells with game objects and scripts and instead do an array in the main script for the data and use world to mouse position for interacting with them

sterile reef
#

maybe this helps you in some capacity

young moon
sterile reef
young moon
sterile reef
#

are you doing it 2d or 3d?

young moon
#

2D with pixel art

rigid island
sterile reef
#

all my "Gameobjects" are Objects (Classes) stored in a mapping dictionary

#

and to access/update i only have to input the position of where i clicked / other logic

#

but if youre working with free-moving enties you can instatiate a gameobject with a sprite and store the transform in the entityData

kind willow
leaden ice