#archived-code-advanced

1 messages · Page 114 of 1

pliant cypress
#

Thanks this is perfect. idk how I didn't find this sooner.

final steeple
#

Not related to your question but something I figure is worth bringing up due to the channel we're in: System.Numerics.Vector4 is almost universally better to use than UnityEngine.Vector4 in code that is going to run under Mono. It is the only type other than Vector and Vector<T> that has support for SIMD at the JIT level in Unity's version of Mono, so it will typically perform better than equivalent code using Unity's Vector4

#

When you don't need tightly packed data it therefore can make sense to use that instead of Vector3 even, sometimes

regal olive
#

If i have a folder with asmdef, then inside the folder there is also a subfolder with asmdef, does the top asmdf automatically refer the asmdf inside the subfolder

stuck plinth
#

nope!

regal olive
#

okay thanks

#

Whats the difference between assembly definition asset and assembly definition reference asset ? If i can refer other asmdef using assembly definition asset, why do i need assembly definition reference asset ?

#

Why does script outside folder with asmdf able to reference dll inside folder with asmdef despite not adding assembly definition reference ? does that imply asmdef only cover cs and not dll ?

#

auto referenced option was unchecked

stuck plinth
#

assembly definitions are for source files yeah

#

plugins have their own reference settings

stoic otter
#

is there a way to check if a object is copied by my artist?
i have an GUID system that an object get a certaint guid when you make them only problem if you copy the object the guid will also be copy't
how to i check if a guid of objects is not the same when the artist copy the object or if the object is copyt

ruby prairie
azure meadow
#

does [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] run only on the first scene load or on each scene load? 🤔

azure meadow
#

Do I have a fancy thing like that that runs on every scene load? 🥺

#

I guess I could hook myself to my own scenemanager after all 🤔

#

SceneManager.activeSceneChanged also works 🤔

sly grove
undone gust
#

Hi, is there any way to increase the NavMeshAgents priority level above 99? I need it for making an RTS with hundreds or thousands of units on screen. I want to use it to make units not overlap in various situations. 100 positions is also very bizarre, it's and Integer, so why only 100 values?

I have made various systems such as moving in formations or keeping group shapes, moving around corners with a random distance for big groups, etc...

But it's still not enough. For example a group of units attacking a single unit ends up having all units overlapping pretty hard. If units that are closer to the target had a higher priority, it would reduce the overlap significantly. But I need to have 100.000 to 1.000.000 priority levels to an achieve this.

Thanks for your time!

frozen imp
undone gust
spare tartan
#

is there a way to create a prefab stage like environment without making a prefab stage? like another way to open a gameobject in isolation

lucid crane
#

I don’t see why you couldn’t just make it a prefab and then apply it. Alternatively, you can lock and hide everything else

compact ingot
spare tartan
vital fossil
#

I want to make a object placement script.. in which object instantiate at the front of the camera on the ground... and there are two categories... one remains on the ground and move where raycast hit.. and other are place on the another object... i can't achieve the placement on the another object

stuck plinth
spare tartan
#

appreciate it, though was just looking to do this for non scene things

misty glade
# final steeple When you don't need tightly packed data it therefore can make sense to use that ...

Cool, thanks. I ended up considering it for a while and ultimately just rolling my own struct that's got the stuff I need from the numerics library and will play nicely with unity. Ultimately I'm going to need tightly packed here - the use case is a Location that's gonna have a lot of low latency requirements (ie, realtime ships). It's for an MMO so the better I can pack down the data, the more people (or smaller tick rate) I can support.

Tentatively my plan is to use a combination of "big location" (vector3 ints - ie, which cube within a map the player is in) and "small location" (vector3 floats - what x, y, z within the cube they're at). Only small location needs to be small and packed, so I'll roll my own for that struct and just do whatever for the big one.

slate spoke
#

I feel semi confident this belongs in this chat lol.

I'm working on a "game", for lack of better descriptor, that's gonna run on the Quest 3 standalone, effectively phone hardware. The game's main gimmick is placing a bunch of individual objects with unique data in pre-determined locations across a giant map, which is procedurally generated for performance. The thing that determines the location of these objects is a large dataset, each datapoint having a set of coordinates.

Here's the issue, though. There's almost 700k data points. That's almost 700k gameobjects.

I have zero clue where to begin on how to make this work. Any guidance would be a blessing.

flint sage
#

In what kind of density

slate spoke
#

this is what the distribution looks like

#

from a quick and dirty python scripted plot lol

#

but they need to be separated enough for the player to be able to interact with them individually

upbeat path
#

when you say standalone will the device have any network connectivity at all?

slate spoke
#

(about 2-4 weeks)

#

the dataset is only about 75MB

#

as a .parquet, at least

upbeat path
#

how many objects do you envisage being active at any one time

slate spoke
#

however many the headset can handle without noticeable performance costs, I think an important part of the experience is gonna be looking out into the horizon and seeing a bunch of em

#

maybe 1-2k at any given point, depending on how tuned in I can get the LOD

#

as well as depending on how many are in a given area, of course

#

the game is moreso meant to be a form of glorified data visualization

upbeat path
#

do you know the film Tron?

slate spoke
#

mhm

#

we talkin the classic one or the disney one?

#

I assume the former

upbeat path
#

classic

slate spoke
#

yeh

upbeat path
#

I'm trying to visualize the kind of data visualization you're talking about

flint sage
#

I'm guessing that thousands of objects rendering at the same time on a quest won't fly, so you'll need to figure out some tricks to render things. Can't really give advice since we have no idea what kind of obejcts you're rendering. Or whether htey need to be interactable

slate spoke
flint sage
#

There's some obvious things you can do like putting things in a quadtree, figure out where the player is and only render close objects

slate spoke
upbeat path
#

I have done something which I think is similar in concept before but I used a backend data processor and used the frontend purely for rendering. That obviously wont work for your prototype

slate spoke
slate spoke
flint sage
#

All objects are interactable?

slate spoke
#

Mhm, the idea is that the player will be able to go up to any of them and view the information pertaining to that specific datapoint

upbeat path
slate spoke
#

Fair yeah

livid kraken
#

I would go for a k-d tree if we just need n closest points

upbeat path
#

you can fine tune the rendering using object pooling and a lod calculation

slate spoke
#

Oh, you mean like reusing the same gameobjects for different datapoints based on what's in view

upbeat path
#

exactly

slate spoke
#

true yeah, that is already what I'm doing for terrain as well

#

they have a means of placing objects with the thing in this video as well, but they're entirely random as far as I can tell

livid kraken
#

In my experience quest 3 can handle around 300k-500k tris so your objects will have to be simple

#

Also chunking them into a single mesh for furthest lod will help

upbeat path
#

do you know how well the Quest handles multi threading?

slate spoke
slate spoke
livid kraken
upbeat path
#

that is gonna be very important, coz you're gonna be doing a lot of it to keep it performant

livid kraken
#

We have run a custom jobified hlod on the quest 2 even

slate spoke
#

dang nice

upbeat path
#

good thing about data visualization is it doesn't need to be complex meshes, generally you can get away with a few primitive shapes

livid kraken
#

The main bottlenecks on a quest are draw calls and fragment shaders

slate spoke
#

True true. When I was first handed this project, the mesh they were using was a photoscan of a real aloe plant

upbeat path
#

forget it

slate spoke
#

yeah that thing's going asap

#

dude the terrain was even worse

#

it was a single 110k tri mesh with a rigidbody

upbeat path
#

rofl, some people think we live in a ScFi world

livid kraken
#

Honestly with the GRD in Unity 6 and decent enough lods you can probably run it

slate spoke
#

I have thought about upgrading the project to Unity 6

#

I might once I have the thing working first lol

upbeat path
#

I think you are going to be stuck with whatever the Quest sdk supports

slate spoke
#

True, I've yet to hear of anyone testing that yet

#

I know one of the hand physics assets I use recently added support for Unity 6

livid kraken
#

Honestly I would go with Unity 6 off the bat and make use of the new tech. The time ghost terrain demo with the millions of grass bjects is exactly what you want to do

upbeat path
#

I think you should forget about the rendering side of things atm, that can be fine tuned later. I would concentrate on answering the question, 'How fast can I calculate which objects are in view'

slate spoke
#

Makes sense

upbeat path
#

I'm guessing the Quest has the standard 30 fps as Android

slate spoke
#

120

upbeat path
#

then you are definitely gonna have to time slice

slate spoke
#

mhm, this is definitely a hell of a challenge lol

#

so, the two methods I've heard of going about this so far are k-d trees and quadtrees, how would implementing either of those work?

upbeat path
#

doing it in itself is not a problem, making it realistically performant definitely is

slate spoke
#

right yeah

#

the definition of being easy on paper lol

#

wait so from what I can tell, k-d trees are basically just 3D quadtrees

#

or is that wrong?

slate spoke
#

does it need to be 3D? The plants could just be projected onto the terrain mesh, no?

upbeat path
#

you will need it to be 3d to get the lod calc correct

slate spoke
#

Ahh, I see

#

well, the datapoints only have an x and y coordinate

flint sage
#

It depends on your terrain, you can likely get away with a quad tree or kd tree if your terrain is mostly flat

slate spoke
#

currently, it's procedurally generated with perlin noise

flint sage
#

That doesn't mean much

upbeat path
slate spoke
#

I think the customer will want some height variation

#

occasional sand dunes might make culling easier as well

flint sage
#

So you mght need something 3d, but you probably want to project your data points onto the terrain ahead of time

#

So that you don't need to do all that crap at runtime

upbeat path
#

because your data is static, a serialized, chunked octree is probably the best data structure. Unfortunately it's also the most complicated to implement

slate spoke
#

that can def be done

flint sage
#

(since your datapoints are only 2d)

slate spoke
upbeat path
#

unlikely

livid kraken
slate spoke
#

Oh nice

#

One thing I'm also concerned about is how actually accessing the data associated with the datapoint is gonna work

#

cuz I assume these are just to store coordinates

flint sage
#

Well you haven't said anything about that data so no idea

#

Is it just text?

slate spoke
#

Just strings, yeah

flint sage
#

Idk how the above kd tree works but it likely allows for custom data

slate spoke
#

well, strings and ints

flint sage
#

So you can likely just make a class that contains your stuff and put it in there

#

Or have some identifier that you can then look up somewhere else

slate spoke
#

yeah I was thinking something along the lines of just assigning it an ID corresponding to it's datapoint, just not knowledgable on the logistics of that

flint sage
#

Not sure there's anything special to it?

upbeat path
#

I think you've got a lot of research and experimenting to do. 2-4 weeks is gonna be pushing it to get even a proof of concept working

slate spoke
#

yeah no kidding

#

nerves are high, won't lie

#

especially since they're gonna use this to apply for a grant

#

which, if they get the grant, they get the means to hire people, and I'd be their first candidate

flint sage
#

So what do they actually want

#

Because it's a lot easier to do something smaller scale

#

I.e. without 1000s of objects

slate spoke
#

a proof-of-concept that uses the full main dataset, as far as I can tell

flint sage
#

With some lightweight objects, culling, etc, you can get a few hundred objects without issues likely

slate spoke
#

up until recently they've been using a different dataset of about 20k datapoints for prototyping

flint sage
#

Hell, it might be worth just throwing everything at it and testing performance

#

(with aggressive culling and LODs)

slate spoke
#

true, and yeah to a point lmao

upbeat path
#

I have to say even having done this kind of stuff before, a 2-4 weeks time frame is totally unrealistic

slate spoke
#

I didn't just start on this necessarily, ideally we'd have the full semester to work on it

#

and ideally I'd have a full group of 5 members to help me out

scenic forge
#

If the data is known ahead of time, you don't need any of the tree data structures. Just have a grid instead, splitting your entire space into cells and putting each object into the cell it belongs.
Those tree structures are good when you need to modify the data at runtime (insert/delete/etc), which is not your case. Grid is so much easier to implement and has better performance, especially so if you carefully choose your cell size.

slate spoke
#

but the odds are kinda stacked against me lol

upbeat path
#

that helps

scenic forge
#

It does not matter

slate spoke
#

there'd be a lot of empty cells lol

scenic forge
#

Which is a non factor unless you are worried about running out of memory.

upbeat path
slate spoke
#

thus why I implemted the infinite procedural terrain thing

slate spoke
upbeat path
#

@scenic forge suggestion is workable, but you would need to calculate the memory requirements

#

you only need 1 bit per grid cell and if you can chunk the grid you get the benefits of both size management and speed

slate spoke
#

That does sound appealing

scenic forge
#

You can do some napkin math to see if your entire world fits in memory or not, but even if it doesn't, the good thing about grid is that you can easily stream it rather than having to load the entire thing in memory.

slate spoke
#

I assume having the terrain be procedural definitely helps in that regard

upbeat path
slate spoke
#

prolly wouldn't be infinite otherwise

upbeat path
#

not a benefit, that will consume a lot of your fps

#

does it need to be infinite given that your data points are static

slate spoke
#

Probably not in theory, but I only know that the generated terrain stuff I got from the video I sent earlier performs vastly better than any of my own attempts lol

#

it's less so generating meshes more than it is just modifying pooled ones

#

it's just a single continuous perlin noise thing for the heightmap, and the vertices are kinda just projected onto it

#

I think the only performance it would eat up is when moving

upbeat path
#

I'm guessing that performance is your major concern so the less you can do at runtime the better, so a predefined chunked terrain would work better

#

again, you can fine tune the chunk size for performance

slate spoke
#

That's fair. I guess I would need to figure out how to have that many chunks already in the editor while getting performance as good as what this current thing has

upbeat path
#

you need to look at implementing your own serialization system

slate spoke
#

gotcha, hmm

#

well, this would only kinda work

#

actually honestly seems like this would be worse

#

it doesn't serialize meshes, only stuff like terrain component data and heightmaps

#

which also implies having hundreds of heightmaps

slate spoke
#

which I think was why my previous attempts at runtime terrain generation went so poorly, but maybe that's just because I was generating the heightmaps

slate spoke
#

One thing I should mention as well for the sake of futureproofing I suppose, one idea the customer really likes the idea of is having a way of tracing paths between all of the datapoints that players move to and from, and updating the terrain textures accordingly for all players

#

that I obviously don't need to implement soon, but if that impacts any of this, I assume it's worth accounting for

upbeat path
#

nah, detail, not important

slate spoke
#

I'll take your word for it then lol

upbeat path
#

lol, I've already written half the system in my head whilst we've been having this conversation

slate spoke
#

man this is why I regret doing university so often

#

I would know so much more about Unity and programming in general had I spent the past 4 years actually doing Unity stuff instead of random irrelevant classes

#

like good lord I could've already had 4 years of experience doing nothing but unity

upbeat path
#

full disclosure, I have been doing this stuff for 50 years

slate spoke
#

valid lmao

upbeat path
#

it is an interesting task, the data structures required are fairly simple. The problem arises with scale and it will be how you handle that scaling that will make or break the project

slate spoke
#

I agree that it's interesting lol, funny how these kind of things can be so simple conceptually and yet so semantically challenging

upbeat path
#

the devil is in the detail, as always

slate spoke
#

also worth mentioning, idk how much it matters with this obv running on my PC, but like with the terrain sprawled out about 200m in every direction, I'm still getting 600fps

#

I screenshotted a low frame apparently

upbeat path
#

not really relevant. you wont get that on a Quest

#

not even close

slate spoke
#

yeah fair

upbeat path
#

so there's a good thing to start with. Build that to the Quest and see what you actually get. that will give you a benchmark to work with

slate spoke
#

good point, I'll do that rn

slate spoke
#

..man I forgot how long these take to build

upbeat path
slate spoke
#

that'd explain a lot lol

#

alright got it going now

#

..and also realizing I don't have a way to benchmark the quest 3 performance when running directly on the headset

#

the most I can say is that it feels butter smooth lol

#

but also the terrain generation isn't working, so uh, maybe that means nothing

#

well kinda

upbeat path
slate spoke
#

it's not generating anything after the initial generation

upbeat path
slate spoke
#

hmm.. it's still working in the editor

#

oh wait I know why

#

it's cuz of how vr tracking offsets are set up

#

ez fix

#

he says, naively

slate spoke
#

okay the player recentering is kinda buggy with VR but that's earning itself a //TODO:

#

yeah I don't notice any framedrops

#

lemme find a way to properly test this tho

#

alright here we go

#

It's locked to 72 fps cuz I have something misconfigured I think but the drops are there

#

Just, really tiny

upbeat path
#

that ain't good, not going to give you much wiggle room

slate spoke
#

I think it can do way better

#

CPU/GPU usage is tiny

upbeat path
#

it needs to. this is the simplest part of what you want to do. the cpu intensive stuff has to be added

slate spoke
#

Yeah fair

upbeat path
#

forget the CPU/GPU usage FPS is ALL that counts

#

even more so with AR/VR than desktop/mobile

slate spoke
#

Right, I'm just saying the cap is currently 72, which it's hitting easily lol

upbeat path
#

do it, get the max possible you can

#

URI said you should be able to get 120 so that has to be your aim

slate spoke
#

damn it, can't figure out why this isn't working

#

ah well, I'ma call it in for the night. I'll start up on this again tomorrow

#

it's like 6am lmao

upbeat path
#

you're East Coast USA?

slate spoke
#

Mhm!

void bronze
#

I don't know if this is the right place to ask, but I have a multiplayer unity project. In my project, on a single client, I have a texture that I draw to at about 60fps. I need to take that texture data and somehow provide that data to every other client. I'm using Unity's netcode for gameobjects at the moment but I'm open to other tools.

Unfortunately, the code I'm running to calculate the data for the texture cannot be simulated on other clients.

I know Unity isn't really optimized for streaming textures across the network (let alone multiple textures which I'll eventually need to be able to scale to), but are you aware of any tools / packages that might offer some help with this.

sly grove
#

so maybe that's what you want

void bronze
# sly grove > Unfortunately, the code I'm running to calculate the data for the texture cann...

Yeah, I'm aware that not being able to simulate the code on other clients isn't ideal. If I could then that would make things a lot simpler. It's a bit too complex to go into, but I am actively trying to figure out a work around as video streaming is a last result. Thanks for linking the resource. Do you know roughly how network / bandwidth intensive the video streaming will be? The textures are about 250 pixels in width and height, updating at about 60fps. Also, I appreciate that this is just theory right now, but do you have an idea on how well this could scale for streaming multiple textures?

sly grove
void bronze
#

That's fair enough. Thanks anyway, I'll take a look into it. All of the resources I found while googling were for paid assets (which I don't mind), that weren't actually relevant to my situation

somber pendant
#

Hey friends, I'm trying to add an external DLL in my project in assets/plugins. My project is 2022.3.36f1 and the DLL targets .NET 3.5

I am not able to reference anything from the DLL in my project so I am wondering if it's due to the DLL not being valid?

#

Due to targeting net3.5

#

I don't see any errors in the editor, it just seems to not be adding references to the DLL in my csproj when it generates it

upbeat path
#

targeting .Net 3.5 is fine

somber pendant
#

Hmmm, it is set to auto reference so I'm not sure why I can't use it at all

upbeat path
#

screenshot show your project view and the inspector of the dll

somber pendant
#

I was fiddling with platform settings but i assume the default is ideal. In any case i don't seem to be able to reference anything from it regardless

upbeat path
#

you have it set to be excluded in the editor

#

also that looks like it it may be a Win Forms dll which wont work in Unity anyway

somber pendant
#

Where does it mention winforms there?

upbeat path
#

it doesn't, but I can extrapolate from the part of the name that you didn't redact

somber pendant
#

Oh, I think that's just meant to be windows. There are versions of this DLL for every platform like iOS etc

#

It's meant to be a wrapper for a native DLL

upbeat path
#

dll's are platform agnostic, so if it has WIN in the name that generally means it is using Win Forms specific code which wont run in Unity

somber pendant
#

Idk, I have a folder for each platform with a DLL for that platform which uses a naming scheme

#

Like the ps5 one ends with _PS5.dll so the 64 bit windows ending with _WIN isn't surprising for me

thin mesa
upbeat path
thin mesa
#

you're the one who made the incorrect claim 🤷‍♂️

somber pendant
#

In this case I have about 9 different DLLs for various platforms

upbeat path
#

not an incorrect claim at all, read what I actually wrote

somber pendant
#

I personally didn't make these but they each have platform specific logic I'm pretty sure

#

And I don't think they use winforms

#

They are meant to be managed wrapper DLLs for native DLLs

#

Maybe it's an issue with the native DLLs or something?

thin mesa
#

the dll you showed was not included in the editor so it wouldn't be accessible within the editor, only in standalone windows build. there's likely a dll somewhere in that asset that would be intended for use in the editor

somber pendant
#

I changed it back to standalone but no dice 😦

thin mesa
#

steve had just made a wild assumption that it was a winforms dll just because it had "WIN" in its name, you can disregard that assumption

thin mesa
somber pendant
#

In platform settings it has editor and standalone

upbeat path
somber pendant
#

If I change it to all platforms it doesn't seem to help either

thin mesa
#

i did. you were just wrong

upbeat path
thin mesa
#

and yet it wasn't. it was a dll that had been compiled specifically for the windows platform.

somber pendant
#

Oh I got it working

#

I had to make it work for all platforms

#

Seems wrong but I'll figure that out later

thin mesa
#

are you certain that was even the one you should have been modifying the import settings for? either way, you probably need to exclude the other platforms rather than making it available on all (if you're not actually building for any other platforms then it wouldn't really be a problem if you don't do this, but it is definitely recommended to do so just in case)

upbeat path
#

when you are using dll's and you have multiple platform specifc ones.

  1. They should each be in a distinct folder under a Plugins folder
  2. They should all have the same name
somber pendant
#

I'm testing on x64 and using just Standalone didn't seem to work

upbeat path
#

because x64 is for a build not in editor

somber pendant
#

Editor being included must have done the trick

thin mesa
#

so just to confirm, what you've actually done is just remove the Editor from the excluded platforms, rather than going and including all of the others in the box further down, right? because that was what was pointed out when it was said you have the editor excluded

slate spoke
thin mesa
upbeat path
thin mesa
#

I'm sure in your 1000 years of using computers you've come across one or two dlls that perhaps were compiled for specific platforms. and those settings are to tell the editor which platforms to actually use those dlls on. which you would naturally know if you'd stop being so arrogant and maybe read the docs or something
https://docs.unity3d.com/6000.0/Documentation/Manual/plug-in-inspector.html

scenic forge
slate spoke
#

Like is there specific scripts I should be writing or a certain thing I need to mess with in the editor or something?

scenic forge
#

It's not much different from reading/writing a game save.

pastel finch
#

Any mesh experts around? I'm trying to make two pieces of terrain and stitch them together manually. I'm just looking for technique suggestions.

austere jewel
#

If you have a question just ask it

slate spoke
#

I'll look up some guides for that tho, thanks

raw dew
#

Anyone here an Mlagents expert and can take a look at an AI I’m currently training?

terse inlet
livid kraken
#

Hey, I'm trying to use the gpu Sparse uploader to write to a graphics buffer that holds hit positions for a shield vfx. Like so ``` public unsafe void RegisterHit(int id,float3 pos)
{

float4 newHit = new float4(pos, 1);

m_gpuUploadOperations.Add(new GpuUploadOperation
{
    Src =  &newHit,
    DstOffset = id + _iterators[id/k_MaxHitsPerShield],
    Size = k_sizeOffloat4
});
_iterators[id / k_MaxHitsPerShield] = (_iterators[id / k_MaxHitsPerShield] + 1) % k_MaxHitsPerShield;

}``` Problem is I'm getting the wrong data in the buffer. I think I might have done an error with the pointer that needs to go in Src but I’m not sure.

untold moth
#

Try making it a class field(assuming that object lives long enough) and see if that fixes the issue.

livid kraken
#

My god I think you are right

livid kraken
#

@untold moth that was it. Thank you. This is what I get for using unsafe code while sick. 😄

untold moth
livid kraken
brave cairn
brave cairn
livid kraken
#

I’m not sure I will have to check. Right now I also have to manually calculate the total and biggest uploads and supply that to the sparse uploader

livid kraken
untold moth
brave cairn
untold moth
livid kraken
brave cairn
# livid kraken I was thinking the same I would just need to do &allHits[i] right ? Sorry my poi...
using Unity.Collections.LowLevel.Unsafe;
using Unity.Mathematics;
using Unity.Rendering;
using UnityEngine;

public class SparseUploaderDemo : MonoBehaviour
{
    SparseUploader sparseUploader;
    GraphicsBuffer gb;
    
    void Start()
    {
        gb = new GraphicsBuffer(GraphicsBuffer.Target.Raw, GraphicsBuffer.UsageFlags.None, 0xffff, UnsafeUtility.SizeOf<float4>());
        sparseUploader = new SparseUploader(gb);
    }

    void Update()
    {
        var uploadOperationsCount = 10;
        var valueSize = UnsafeUtility.SizeOf<float4>();
        var threadedSparseUploader = sparseUploader.Begin(uploadOperationsCount * valueSize, valueSize, uploadOperationsCount);
        
        for (int i = 0; i < uploadOperationsCount; ++i)
        {
            var uploadedValue = new float4(i, i, i, i);
            threadedSparseUploader.AddUpload(uploadedValue, i * valueSize);
        }
        sparseUploader.EndAndCommit(threadedSparseUploader);
        // Now graphics buffer will have updated data, and can be used in shaders
    }

    void OnDestroy()
    {
        sparseUploader.Dispose();
        gb.Dispose();
    }
}
#

Something like this

livid kraken
#

This seems much simpler than what I’m doing I will have to give a try thank you❤️

trail quail
#

Hrm, if I need a threadsafe read/write to an array - how do I do that in ecs?

#

like if I want to increment a value in an nativearray<int> - in a parallel job, how can I do that reliably?

#

(forgive me if there is a dots/ecs channel im not using)

slate spoke
#

Gonna be hard to explain properly what I'm trying to figure out so bare with me here.

Basically, I'm trying to read .parquet files in Unity. To do so, I'm following this tutorial for figuring out how to read/write game data. https://www.youtube.com/watch?v=mntS45g8OK4

However, this tutorial is for messing with .json files, using the Newtonsoft Json Unity package. As far as I know, Unity doesn't have an equivalent package for parquet, so I had to use this (https://github.com/GlitchEnzo/NuGetForUnity) to then install this (https://www.nuget.org/packages/Parquet.net/).

Once that was installed, I modified the tutorial code as best as I could in a way that would allow me to read a roughly 74MB .parquet file currently located in my assets folder. I hit play to see how it ran, and.. it's been stuck at the compilation phase for about 30 minutes.

Learn how to save and load data in Unity - avoiding common mistakes and dangerous serialization techniques many other tutorials will tell you to use!

In this video we'll look at using text-based serialization using JSON and optionally encrypt that data. I also discuss some of the pros/cons for using text-based serialization, and what you should...

▶ Play video
GitHub

A NuGet Package Manager for Unity. Contribute to GlitchEnzo/NuGetForUnity development by creating an account on GitHub.

#

@upbeat path @scenic forge y'all know the context of why I'm trying to do this, what do y'all think of how I'm going about this?

mighty flame
slate spoke
scenic forge
#

Not sure why your compilation seems to be stuck, but is there a particular reason you want to use Parquet?

scenic forge
#

How much data is there?

slate spoke
#

75MB, about 676k datapoints

scenic forge
#

I'm not familiar with Parquet to know, it does seem like it has some sort of data streaming though rather than having to put the entire thing in memory

#

Personally the approach I would go for, is to preprocess those data at build time into a format that's more friendly to runtime, and additionally chunk them based on your runtime requirements.

#

This way you don't need Parquet at runtime at all, and your data can be in a format that's flexible and tailored to your runtime needs.

slate spoke
#

Is there a specific format you would recommend for that?

scenic forge
#

Very likely just binary.

slate spoke
#

How would I go about converting it to binary?

scenic forge
#

Design some sort of schema, eg "first 4 bytes is a floating point for the X coordinate of the first data point, second 4 bytes is for the Y coordinate, and repeat for all data points" then just read/write to it.

slate spoke
#

I would need to do that for every element of the datapoints

#

not just the coordinates

scenic forge
#

Of course.

#

You pay for convenience with performance/flexibility. Whether that tradeoff is worth it or not, you need to evaluate yourself since I don't know what Parquet gives you.

#

I know for sure that if your data is packed in a structured way, you can easily skip to a certain part of the data without needing to have the whole file in memory.

slate spoke
#

I think the main benefits of parquet are supposed to be performance and file size

scenic forge
#

There are also more general formats that aims for a middle ground, like FlatBuffers.

raw dew
#

anyone can help me figure out why my script is not working on my own ragdoll? I'm trying to control the joint on that part and it works on another ragdoll just not mine 😦

#

maybe my ragdoll setup is wrong or smth but idk anymore I'm losing my mind

rare lark
#

Building off of a previous question: How can I templatize a set of input parameters, given that I don't know what the parameters will be, nor do I know how many there are? [Here's the relevant code snippet](#1304612190887608412 message)
However, ideally I have Func<X, bool>, where X somehow represents, say, <int,float>,<string,int,int>, or whatever it may be

terse inlet
# slate spoke How would I go about converting it to binary?

The serialization and deserialization is done via FastBufferWriter and FastBufferReader. These have methods for serializing individual types and methods for serializing packed numbers, but in particular provide a high-performance method called WriteValue()/ReadValue() (for Writers and Readers, respectively) that can extremely quickly write an en...

terse inlet
fathom geode
#

Need help with some movement code: Whenever the player goes up a slope, his speed gets subtracted by the sin of the slope's angle multiplied by a value called slopeUp, but he can still move up the slope because the code that handles movement based on the player's input is still active and incrementing the speed. Same for when he goes down a slope, but then turns around mid descent and goes up. Is there a way to fix this and make the player go down naturally if he can't climb the slope? https://hastebin.skyra.pw/kixedinaro.pgsql

fleet sleet
#

what does this refer to in a unity C# closure?

#

this in the object that creates the closure or this in the object calls the closure?

fathom geode
#

Oh wait, you're refering to the keyword "this"?

untold moth
fleet sleet
#

I'm trying to create an event listener as follows

#

this is the member: public Action<string> OnWord;

#

Word wordObject = this;
voiceController.OnWord = (string word) =>
{
voiceController.uiText.text = "drawing word";
// wordObject.drawWord(word);
};

#

this does not work

#

also drawWord isn't called

#

I do know that the voice controller works, but for some reason the communication between my objects fails

#

drawWord is an async function by the way

#

it is supposed to run without being awaited

fresh salmon
#

You should most likely use a public event Action<string> OnWord instead, this facilitates multicasting (subscribing multiple handler methods to the event), and subscribing with += instead of just assigning the lambda with = (which means you'll also need to unsubscribe with -= when you don't need the handler to be called anymore)

#

drawWord() is commented out so it effectively will not be called here

#

Make sure you are invoking the event at some point by placing logs inside the lambda and/or by setting debugger breakpoints

fathom geode
obsidian stump
spice trail
spice trail
spice trail
#

It will make your slope problem a simple trigonometry
here is how raycasts(green) would look like on player(gray) on the slope (white)

#

hypothenuse can also be got by substracting world coords of two ray hits and getting its magnitude

#

so its more of SSS triangle in this case

fathom geode
#

Thanks

spice trail
#

(less math heavy option would try to get rotated in wolrd coords player eulers forward vector and get vector3 angle with hit normal but i have not yet tested)

dusty wigeon
spice trail
#

though it does create some heavy math(its atan functions which are while not the most costly thing i did in update, are not welcome guests)

fathom geode
#

Again, when climbing on a slope, speed is decreased as intended, but it's immediately incremented by the code that handles movement based on player input, which causes it to never reach zero and continue to crawl up the slope

carmine lion
#

nmv i forgot to save all project

cold breach
fathom geode
rare lark
#

Again, when climbing on a slope, speed

cold breach
#

Your falling state is probably good enough to handle sliding down most of the time.

slate spoke
slate spoke
#

apparently there was already stuff built in for it. C# public async Task<DataFrame> LoadParquet<T>(string parquetFilePath) { DataFrame df; using (System.IO.FileStream stream = System.IO.File.OpenRead(parquetFilePath)) { df = await stream.ReadParquetAsDataFrameAsync(); } return df; }

cold breach
#

You could also look into reverse engineering this behaviour from this addon.

rare lark
#

Any elegant way to chain a bunch of method calls until a value is not null?

Value v = might_be_null_1();
if (v==null) { v = might_be_null_2();}
if (v==null) { v = might_be_null_3();}
if (v==null) { v = fallback();}
// ...

Ideally, I'd like something like:

Value v = might_be_null_1(
  ).might_be_null_2(
  ).might_be_null_3(
  ).fallback()
sly grove
#

The only thing is

#

this only works if Value is not derived from UnityEngine.Object

rare lark
#

okay, interesting, good to know
that looks sexy, thank you

slate spoke
#

the whole dataset is s spread across values from about -20 to 25 on both x and y, but they're so dense in the middle that even a 0.5 by 0.5 section has over 3k datapoints

#

and a 1x1 area has over 10k

#

assuming my math isn't wrong, that would mean that to have world chunks that don't have more than 1k datapoints, we would need about 32400 chunks

#

which sounds.. extremely unrealistic

mystic pike
#

I have issues with my Unity Online Code... I am trying to rename the player objects that spawn with the player name they input so that when everyone else joins, names register

scenic forge
#

Chunk size matters in a few ways:

  • If player needs to access one single corner of a chunk, the entire chunk has to be loaded. This means that if you think of player's view, all the chunks have to cover it, and there will be parts that player can't see but you still have to load into memory and process. The smaller your chunk size, the less wasted space you have to load.
  • On the other hand, if you have a large chunk size, then player can move around for longer without crossing a chunk border and game has to load/unload more chunks. Since loading/unloading chunks is disk IO, it will be slow and you want to minimize this.
  • Depends on what's in each chunk, for example if you have objects that have real physical dimensions, then an object can be in two different chunks at the same time if it's on a chunk border, which means when loading chunks you need to then remove duplicates. The smaller your chunk is, the more duplicates there are and more processing is needed.
    You have to balance all these factors to find a good chunk size.
slate spoke
#

What I was talking about earlier was in the context of how many objects the Quest 3 is able to handle at once

#

In order to have chunks that only contain as many objects as the Quest 3 is gonna handle, if my math earlier was right, that would total to 32400 chunks

#

the actual physical scale of each individual chunk will still be massive

#

all of these objects have to be at least spread out enough to be able to be interacted with individually

#

My concern isn't the density of the chunks loaded in moreso than the sheer number of chunks that would need to be stored

scenic forge
#

How many objects you can show at once is not relevant to how you chunk them.

slate spoke
scenic forge
#

So that you don't need to have the entire world (not just the part player is currently seeing) in memory.

#

There's no point in loading objects that are 1000 meters away if the player can only see 10 meters.

#

How many objects player can see within that 10 meters, doesn't really matter.

slate spoke
#

I don't think we're on the same page lol

#

I'm not concerned about chunking the actual terrain itself

#

I assumed the reason why chunking was brought up was as a means of loading and unloading the objects in each chunk

scenic forge
#

Yeah that might be where the communication failed. Chunking is just an optimization for not having to load the entire world in memory and only the parts player can see.

slate spoke
#

Right. I'm just trying to figure out the best way to not load in almost 700k objects simultaneously lol

scenic forge
#

Is the player seeing 700k objects at once?

slate spoke
#

No, but the goal is to allow them to see as many as possible extending towards the horizon

#

as many as the Quest 3 can handle

scenic forge
#

Well the horizon is infinitely far away, so it would include literally every single object in that direction.

slate spoke
#

I'll also have a fog effect at a certain point, of course

scenic forge
#

That doesn't mean it's useful to the player, player cannot realistically manipulate an object so far away that it's only one pixel on the screen.

#

At a certain point you still say "okay this is far enough away that even if the objects were visible, players can't use it anyways"

slate spoke
#

the point of the game is that visual, communicating the sheer volume of data

#

but I get what you mean

scenic forge
#

Exactly, once you set a parameter like "player can only see objects within 10 meters" then chunking comes back into the situation, allowing you to only load parts of the world that's 10 meters around the player, rather than the entier world and 700k objects.

slate spoke
#

that's what I was talking about earlier

#

if we were to use that method in a way that would actually be effective for performance, that would mean having tens of thousands of chunks

scenic forge
#

No your calculation is based on density, which is irrelevant to how you should choose your chunk size.

slate spoke
#

Is density not the core problem?

scenic forge
#

No.

scenic forge
#

None of these factors are directly affected by density of objects inside each chunk.

slate spoke
#

I feel like this conversation is starting to circle

#

I'll try to explain this the best I can

#

My current issue is that I need to figure out the best way to load as many objects in the player's view as the Quest 3 can handle, and nothing more, because it can't handle much.

If the loading and unloading of objects happens with the loading and unloading of chunks, then the logical consequence of that is that chunks with a higher density of objects loads in more objects. So, in order to prevent any chunk from loading in too many objects, the number of chunks that make up the world would need to be increased.

scenic forge
#

That's less of a code issue and more of a design issue. Let's say in player's view, there is no object except 1 that's so far away that it's basically unusable by the player, would you still load that? Or let's say player is currently standing in the densest part of the map and surrounding by way more objects than the hardware can handle, would you only load just the amount of objects the hardware can handle, to the point where player can't see objects a few feet away because it exceeded the limit (and player walk a step forward then suddenly they pop up in front of them)?

#

You need to solve this design issue first before thinking about code, especially the latter case, that wouldn't be good player experience.

slate spoke
#

Objects are only gonna be useable when you walk right up in front of them. This game is meant to be a form of data visualization, so making sure the player can see objects too far away to use is still important.

The density of chunks in a given area would be accounted for by just making the overall world larger, spreading out the distance between every object

#

It should be mentioned that this world is going to have a massive physical scale

#

that's why my current terrain implementation procedurally generates infinite terrain at runtime, because while the world technically isn't infinite, from the player's perspective it might as well be

scenic forge
#

"Making the world larger" is the same as making the maximum view distance smaller for the player, so you've taken the approach that "limiting maximum view distance of the player such that visble objects at any given time can never exceed what hardware can handle"

#

And once you figure out that view distance, choosing the chunk size is again no longer related to density.

slate spoke
#

high density would be a worse player experience

#

because all the objects would be right next to you and the rest of the landscape would look empty

#

but either way, yes, that is what I'm trying to do

scenic forge
#

My point is that your problem is a two step process, the first step is to "scale the world up"/"limit the view distance" so that visible objects don't exceed hardware capability, and only after that, you do the second step of chunking the world, at which point density is no longer a factor.

#

But yes I think we are on the same page now.

slate spoke
#

Yeah, it's just difficult to test when I don't currently have a means of loading in only the objects I need loaded in

#

changing the scale is trivial honestly, it'd just be multiplying the value of each point's x/y coordinates

slate spoke
#

so many that I'm worried there wouldn't be much benefit to the chunking in terms of quickly loading in the correct objects

#

where would it go from there, making chunks of chunks?

scenic forge
#

Why would the number of chunks matter?

#

You only load the chunks near the player.

slate spoke
#

Like from what I understand, without any optimizations to how only the necessary objects are loaded in, the strategy would be to just read through the coordinates of all 700k datapoints every time the player is moving to check which objects do or don't fall in range of the player.

Chunking helps with that by having a much smaller list of objects to go through for each chunk, but because there would be tens of thousands of chunks, we're right back where we started of having to sort through a massive list every time a player moves, just now with chunks instead of objects

scenic forge
#

No that's not how chunking works.

#

Let's say you split your world into 10x10 chunks, and player has a view "radius" of 20, and the player is currently at (45, 55), then the player can see from (25, 35) to (65, 75). So you only load all the chunks that would cover that area, which are chunk (2, 3) (which covers (20, 30) to (30, 40)), (2, 4), etc, all the way up to (6, 7).

#

You don't load the entire world and then go through one chunk at a time and test if that chunk's objects is within player's view one by one, you only test the objects within the visible chunks.

slate spoke
#

I already understood that the objects would only be dealt with after the chunks, but I understand now I think. Instead of having to search for all of the chunks in range of the player, you just get the chunks directly because they're indexed

scenic forge
#

Yes, and that's why earlier I suggested to process your data and stored them in a way that allows random access, so rather than "in order to load chunk (42, 69) I have to find the file that contains in and load that file" you can instead "have all chunks stored in the same file and keep that file open, in order to load a chunk I just need to calculate the offset in that file and go directly to it"

slate spoke
#

Gotcha, that all makes sense now lol

#

The only thing left for me to figure out would be actually setting that up

#

Which is straightforward enough for except how to actually load/unload stuff, since I haven't done a lot of that yet. I do have a bit of a grasp on how serialization works, but I've only seen it in the context of saving information that's made in-game

#

I'm not sure how you go about having the game start off with the information already in

#

That's at least the current issue I'm having with loading the .parquet into the game. I am able to get it read in the editor, but it isn't doing the same in the headset

#

I'm guessing the culprit is the use of filepaths to get the .parquet file, but I'm not sure what the alternative is

#

Apparently AssetBundles are a thing can be used in this case I think, but idk

upbeat path
tawny star
#

tourist from code-beginner here

#

walking into this channel feels like staring into the sun

#

just wanted to say that, thxbye

glacial obsidian
glacial obsidian
#

Interesting read

#

i vote they get rid of it only for my selfish convenience! useful logging info be damned

#

too bad im 10 years late to the vote

rotund tundra
#

Does anyone have a good way to get consistent frame times within unity

#

I need to get it as close to 16.7 ms as possible

scenic forge
#

Should've had a sane design like gameObject.IsAlive rather than this weird magical == null that means something different than is null.

untold moth
untold moth
rotund tundra
#

need some sort of alternative to target frame rate

#

right now i have a timer running on a seperate thread, but I was wondering if there is something better

untold moth
rotund tundra
#

its for a fighting game, so its important that frame times are as close to 16.7 ms as possible

#

also i need it to be accurate so i can sleep the game

rotund tundra
#

well actually it's 16.66, but either way I just need some way where i can input a frametime and quickly swap from frame times

untold moth
#

The aim is 60 fps, no?

rotund tundra
#

yea its 60

untold moth
rotund tundra
#

the one i have is precise atm, but a bit heavy on the CPU

#

and yes unity target frame rate is not accurate

untold moth
#

How is it not accurate? How do you confirm that? What values do you see?

rotund tundra
#

using profiler and by just playing online

untold moth
#

What exactly are you looking at in the profiler?

rotund tundra
#

the frametimes

untold moth
#

Also, maybe just try printing delta time and seeing what value it has every frame.

#

Ideally, use fixed update for you logic if you want it to be absolutely precise.

untold moth
rotund tundra
#

I can give fixedupdate a try

#

one sec

#

you can see it here

#

left is using regular update vs my custom frame lock system

untold moth
rotund tundra
#

yes this is in editor

untold moth
#

If you're gonna be profiling for something precise like that, you should be profiling a build.

rotund tundra
#

i see can do

#

i'll try swapping over to fixedupdate and see if it makes a difference

#

yea looking into it a bit more, it needs to be in update

#

fixedupdate isn't tied to framerate

fresh eagle
#

quick question guys

untold moth
#

You won't get more precise delta time than in fixed updated as it's actually a constant(in the sense that it doesn't change over time).

fresh eagle
#

@untold moth when you finnish with him mind being my mentor for a bit while i get the basics of coding?

untold moth
rotund tundra
#

i need it to be called every frame

#

im not understanding

untold moth
rotund tundra
#

im not gonna sit here and explain why, the whole game logic breaks if it's not

untold moth
#

Then perhaps it's an issue with the logic..? I know fighting games in unity use fixed update, I don't know what else to say here...

rotund tundra
#

i dont know if that's case

#

im sure there are games that use fixed update for some logic maybe

#

but its not possible for me to swap over to it atm

drifting solstice
#

i mean you can get fixedupdate to run roughly 60 times a second

#

that's configurable

rotund tundra
#

how can you configure that

#

is it using target frame rate

drifting solstice
#

no, it's completely separate to framerate

#

it's a fixed update

#

framerate isn't fixed

rotund tundra
#

oh i see

drifting solstice
#

it's fixed in deltatime, that's why it's used for physics and timing-sensitive stuff

rotund tundra
#

okay im starting to wrap my head around it

#

i see what you guys are saying now

drifting solstice
#

it's defaulted to 50/s, or 0.02 s per update
i don't have unity open right now so i can't tell you the exact menu, but it's in the physics section in one of the settings menus

rotund tundra
#

oh found it

drifting solstice
#

update is generally for frame-based stuff, like world or rendering changes, or inputs
fixedupdate is for time-based stuff, like physics

rotund tundra
#

just adjusted the times

#

but yea that makes sense

#

im sure this gonna break my whole game tho lmao

#

this is all the different versions

#

left most is fixedupdate, top right is my framelock, bottom right is update

#

does not look like it made a difference rip

untold moth
#

This data that you get now doesn't tell anything at all.

#

Also you're confusing several concepts here.

rotund tundra
#

well ill give that a try now

untold moth
#

Fixed update would be at constant rate, even if the frame time(whatever you're basing your assumptions off) is not constant.

untold moth
wide elbow
#

Decided to ask here because its more about architecture:
I am coming from the web world building UIs and wanted to sanity check the community for options,
If my game is heavily UI dependent, mix of screen space overlay, and world space UI, and need for a bunch of custom widgets is there any must have assets?
I played around with Unity's new UI Toolkit and it was pretty buggy and didnt easily support world space UIs...
basically asking, am I totally good scaling up a system using Canvas and say a UI Manager class or other object oriented design pricniples or is there anything that sticks out as the "React" of Unity for UI?

dusty wigeon
# wide elbow Decided to ask here because its more about architecture: I am coming from the we...

No, not really. I suggest that you use Unity UI instead of UI Toolkit because as you have seen UI Toolkit is not ready yet for production due to lack of feature and lack of maturity.

MVVM, MVC or even MVP are all applicable, but I usually find them more cumbersome than anything else. That being said, given that you are going for a heavy UI oriented game I do suggest you implement some sort of controller to handle the "gameflow" (What comes after what, React to Game Events like notification, etc.)

wide elbow
#

got it thanks for the reply, good to hear.

cinder dirge
#

how can i set a pixel in a texture2d that saved as asset ?

#

at runtime, of course

untold moth
#

Just in case: this is obviously not gonna affect the asset itself(not sure if you're asking that or not).

tired dome
#

hey everyone, when i execute the following code:

public Texture2D CallTakeSnapshot()
    {
        Texture2D snapshot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
        snapCam.Render();
        RenderTexture.active = snapCam.targetTexture;
        snapshot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
        byte[] bytes = snapshot.EncodeToPNG();
        string fileName = SnapshotName();
        System.IO.File.WriteAllBytes(fileName, bytes);
        Debug.Log("Snapshot taken!");
        return snapshot;
    }
    string SnapshotName()
    {
        return string.Format("{0}/Snapshots/snap_{1}x{2}_{3}.png",
            Application.dataPath,
            resWidth,
            resHeight,
            System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
    }

and then i run this code to assign the snapshot to a texture:

spawnedMiniscreen.GetComponent<intelwindow>().optics.texture = GameObject.Find("Camera").GetComponent<campaign_cameraCapture>().CallTakeSnapshot();

it only returns a weird nonexistent texture2D, why is this the case and how do i fix it?

untold moth
tired dome
#

the second image is what comes up when i double click it

untold moth
tired dome
#

i have a different texture saved as a file though

#

is it just an execution order issue? or maybe it takes a bit for the image to load?

untold moth
#

Or is optics the component in question?

tired dome
#

yes

untold moth
#

If it's saved to a file correctly, I can only assume that it's being reset later on for some reason.

tired dome
#

what do you mean by that

untold moth
#

Exactly what I said. The contents of the texture are being overwritten after it is saved to a file.

#

Other than that there isn't really any explanation.

#

Maybe a format issue.

#

You can test that by trying a more common format, like rgba16/32 or whatever it is called.

remote bough
hushed mauve
#

is there a dedicated channel to talk about Unity Sentis?

gloomy sundial
#

can somone guide me making smart ai for my 2d topdown enemies

slate spoke
#

I'm writing a terrain generation script based on one I found in a tutorial. It works, but it only generates terrain with hard edges on every face. I've been trying for the past 3 hours to adapt this function to generate smooth meshes instead, but I never made any progress. Anyone here know the right way about this?

upbeat path
#

!code use a paste site

thorn flintBOT
slate spoke
abstract folio
slate spoke
#

need to make sure this stays performant

urban warren
slate spoke
#

Yeh, I just can't figure out how to make it not do that lol

#

I understand it conceptually, it's just the logistics that's hard to wrap my head around

urban warren
#

They cover sharing vertices and such.

slate spoke
#

like I did when I was following this tutorial https://www.youtube.com/watch?v=NpeYTcS7n-M

Welcome to this series on procedural landmass generation. In this episode we go on a long journey to fix a tiny problem with the mesh normals.

The full source code for this episode can be found here:
https://github.com/SebLague/Procedural-Landmass-Generation

If you'd like to support these videos, I have a Patreon page over here: https://www.p...

▶ Play video
urban warren
slate spoke
urban warren
#
0, 1, 2,
3, 4, 5,

Start at 3:
0 < 1
v /
3   
Then
    1
  / ^
3 > 4

That gives you a square, and then increment to 4 and do the same thing

slate spoke
#

I guess the first step then is to change how the vertices are first made

#

which I assume would need to have it's own for loop before the loop where they get assigned to triangles

long ivy
#

reworking how the mesh is generated will reduce its triangle count and likely a necessary step, but you seem to still not understand the actual problem. You can fix it with your existing solution first

long ivy
#

are you are assigning normals based on the cross product of each triangle. Since every triangle is part of its own quad, there is no smoothing and you get a hard edge

#

you can use your existing solution where there are multiple vertices at each point with split normals, but both of those normals should match instead and be the average of the normals of the two triangles connected by an edge

pure berry
#

Hello, I'm currently coding movements with a Rigidbody for my character. I'm also improving the way I move on a slope. But my problem is that when I'm on a slope, I don't jump as high. I think this is due to the fact that I'm using Vector3.up, but in that case, how can I ensure that the jump height is always the same, regardless of the slope?
Stranger still, when I'm on some steeper inclines than those shown in the video, I can jump even higher than when I'm on flat ground. I'll let you see the two videos demonstrating this.
The only difference I can see is that the second floor is made with ProBuilder and the second with Unity's default cubes.

#

Thanks in advance to anyone who takes the time to read this!

untold moth
pure berry
pure berry
untold moth
pure berry
untold moth
# pure berry Sure! Here it is AirState.cs : https://codefile.io/f/He7xxi2dHr

AirMovePlayer() and AirMySpeedControl() could potentially be affecting your jump hight.
You should probably be logging values of the forces and velocities they apply(and any other possibly interfering code).
Another option is to remove(comment out) all possible factors that affect the player movement during a jump, confirm that the issue doesn't happen, then start enabling them one by one to find the culprit.

#

These are basic debugging techniques. You should really know to do this before asking in this channel.

pure berry
untold moth
#

One thing I'd start with is making a fail proof way of measuring the issue. Just relying on the visuals is a very poor way of debugging.

#

Maybe record the top jump position to calculate the jump hight and log it to the console to see it as an actual number that you can compare.

pure berry
cinder dirge
#

how can i get the instancing id of gpu with mono script ?

untold moth
#

What do you need it for anyway?

cinder dirge
untold moth
#

Control material? Wdym?

#

GPU instancing reuses the same mesh, so if you want to modify the vertex buffer or something, that's gonna affect all the instances

cinder dirge
#

btw, i think instancing id remains between frames

#

i used it in my shader and it keep going on, not jerky so i think it remains

untold moth
#

It depends on the rendering implementation that is closed source, so you can't be sure.

#

It might be changing under different circumstances.

cinder dirge
#

it only change when we add or remove an instanced item

livid kraken
#

@brave cairn Thank you the AddUpload works beautifully.

brave cairn
livid kraken
#

I know Jussi Knuuttila told me about it when I was doing my own BRG renderer. Not sure why he did not mention the add upload thing. I've been using it the "hard way"

#

I think that for the GRD there is now a more "refined" version of it in core graphics but I need to check

#

but just look at how simple the code became ```if (hitRequests.Count > 0)
{
var threadedSparseUploader = m_GPUUploader.Begin(hitRequests.Count*k_sizeOffloat4,k_sizeOffloat4,hitRequests.Count);
for (int i = 0; i < hitRequests.Count; i++)
{

      var id = hitRequests[i].id;
      var hit = hitRequests[i].hit;

      threadedSparseUploader.AddUpload(hit, (id + _iterators[id / k_MaxHitsPerShield])*k_sizeOffloat4);
      _iterators[id / k_MaxHitsPerShield] = (_iterators[id / k_MaxHitsPerShield] + 1) % k_MaxHitsPerShield;
  }
  m_GPUUploader.EndAndCommit(threadedSparseUploader);
  hitRequests.Clear();

}```

brave cairn
livid kraken
#

I think I looked at the entities graphics source to figure out how to use it actually but idk.

brave cairn
livid kraken
#

btw is to safe to dispatch a compute shader to do some work on the buffer after calling m_GPUUploader.EndAndCommit(threadedSparseUploader);

livid kraken
brave cairn
brave cairn
#

Usually workflow is follows:

  • Do all parallel uploads.
  • Make jobs.Complete in one point (to reduce syncpoints to one)
  • Do the EndAndCommit
  • Schedule your compute shaders that depend on uploaded data.
livid kraken
#

@brave cairn hey one last thing you might know how to solve easy. I'm getting a Attempting to draw with missing bindings because at edit time the buffer for the shader is not bound. How can I fix this ?

brave cairn
#

Or, make multi_compile variant with and without ComputeBuffer usage, and switch them between edit and play mode via EnableKeyword

livid kraken
#

Thanks I already did the first approach guess there isn't anything more sophisticated hah

brave cairn
graceful pumice
#

I'm trying to convert this python code I made into C# to work with a fighting game I'm making for a school project:
https://github.com/KingBarou13/Fighting-Game-Input-Buffer/blob/main/main.py

And this is what I've managed to come up with https://pastecode.io/s/rspprb8u

I've run into two problems:

  1. Pressing up twice no matter the space of time between inputs causes Quick Rise to trigger, but no other special moves work
  2. A white box is appearing instead of the input images assigned in the inspector

I've looked over my code a couple times and can't figure out what's wrong with it since it's supposed to be a direct code conversion and it works perfectly in python

GitHub

Input Buffer for a fighting game coded using Python - KingBarou13/Fighting-Game-Input-Buffer

lucid crane
#

speacialMoveExucuted?

lucid crane
#

The problem is that you’re adding to the buffer every frame an input is added, and the way you are checking your inputs makes it so that the additional input breaks the sequence.

cinder dirge
#

how can i set pixel to a texture2d that save as .asset file ?

#

there is no error, it just not changing anything

sly grove
cinder dirge
sly grove
#

I know what you're trying to do

#

I want to see your code.

cinder dirge
# sly grove I want to see your code.
    [SerializeField] private Color colorToSet;
    [SerializeField] private int pixelToSet;



    private void Update()
    {
        matTex.SetPixel(pixelToSet, 0, colorToSet);
        matTex.Apply();
    }```
#

just like this

sly grove
#

ok and what result are you expecting to have here?

#

Are you expecting the file to be updated in the project folder?

#

or just a change at runtime

cinder dirge
sly grove
#

Is the texture cpu read/writeable?

cinder dirge
#

it is .asset file not png

sly grove
#

Regardless,

#

is that true?

cinder dirge
sly grove
#

Ok so how are you confirming that this is not working?

cinder dirge
#

the problem is it is .asset so i can set but it doesn't change

cinder dirge
sly grove
#

It can be hard to see a single pixel..

#

especially with mipmapping and texture filtering

#

It would be better to do something like:

    private void Update()
    {
        Debug.Log($"Pixel before: {matText.GetPixel(pixelToSet, 0)}");
        matTex.SetPixel(pixelToSet, 0, colorToSet);
        matTex.Apply();
        Debug.Log($"Pixel after: {matText.GetPixel(pixelToSet, 0)}");
    }```
cinder dirge
sly grove
#

it's using a different texture

cinder dirge
sly grove
#

How are you getting/assigning the texture reference(s)?

cinder dirge
#

i dont want to use png file because i want to save value out of 0-1

sly grove
#

you can always force your material and your script to use the same exact texture reference at runtime

#

not sure what's going on with the whole asset texture copy thing

empty mango
#

is there any channel for testing questions?

#

im trying to load a scene in setup, but the scene is not loaded during tests, is there a clean way to manage this?

stuck plinth
#

do you mean you're loading a scene and it isn't working?

empty mango
stuck plinth
empty mango
#

also is there a way to find out im in running a test from a method marked with

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Init()
#

because this is my bootstrapper and does some initializations, i dont want it do to that during tests

stuck plinth
empty mango
#

actually

#

i dont think i can, as [setup] marked test code runs after this [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

stuck plinth
# empty mango actually

oh right, yeah this is RuntimeInitializeOnLoad doing what it says on the tin, it's expected to run before any scene loads including entering play mode to run tests

#

if there's something you don't want to run until a particular scene loads, you'll need to put it in that scene or do it some other way

hot arrow
#

Does anybody know if its possible to set the unity assetbundle name after the assetbundle hash has been generated?
My use case involves putting the hash in a specific place <hash>/<assetbundle name>, I've tried using BuildAssetBundleOptions.AppendHashToAssetBundleName but that outputs <assetbundle name>_<hash>

(Originally posted in #archived-code-general before I moved it here because I think it'd be an advanced concept)

empty mango
#

maybe that would be ok, probably bit hacky

hot arrow
#

Build the asset bundle, get the hash, then just build it again with the new name

#

Hash isnt changed since thats not something that influences the hash

stray raptor
#

Hi!

#

I'm making a roguelike and would like to generate maps that look similar to this

#

anyone have an inkling as to how I could do this?

nova ridge
#

Prob add X number of Vector2's to a list, always one next to another and with a randomness factor, and then fill the rest of the grid with tiles

#

Hey! Im making a tweening library from scratch, and I have reached the point where everything left to do is optimize it!
I am currently reaching around 200 fps with 7000 + active tweens, but I do experience lag spikes when multiple tweens are either created or destroyed at the same time. These are the responsible code:

public void AddTween<T>(IPTween tween)
{
    TwCount ++;

    if(LogLevel > 0)Debug.Log($"Created tween: {tween.Identifier}");

    _activeTweens[tween.Identifier] = tween;

    _currentActive =  System.Linq.Enumerable.ToArray<KeyValuePair<string, IPTween>>(System.Linq.Enumerable.AsEnumerable( _activeTweens));
}
#

And the constructor per se:

public Tween(object target, string id, T startV, T endV, float time, Action<T> tweenUpdate)
{
    if(time <= 0f)
    {
        throw new IndexOutOfRangeException($"Cannot Tween a value out of bounds ({time} is less or equal to 0)");
    }

    Target = target;
    Identifier = id;

    _startVal = startV;
    _endVal = endV;
    _time = time;
    _onTweenUpdate = tweenUpdate;

    PatoTween.I.AddTween<T>(this);
}
regal lava
#

That's a lot of tweens. Any reason you can't just reuse them instead of destroying?

regal lava
stray raptor
#

Ah sorry, wasnt sure where to ask for help on pcg

stray raptor
#

Thanks! Ill look into it

nova ridge
#

And don't get me wrong, I'm pretty happy with the performance, but if I can push it a little bit further, I'll do, just it case

grizzled valve
regal lava
rough sky
#

Is it just me or has Unity 6 broken much of the URP render feature/pass functionality?

#

After my render system stopped working, I have gone back to the docs to find the examples there don't seem to work either

slate spoke
#

I'm working on a game for Quest 3 standalone that loads in a local .parquet database and stores terrain chunk info on disk. Currently, the framerate when loading in the dataset initially is pretty rough, and there's slight frame drops whenever loading in terrain chunks. I want to make the experience smoother by loading these things slower and in the background, but apparently there's no way to do multithreading on the Quest 3, at least easily. How would I go about doing all of this on the main thread without framedrops?

nova ridge
upbeat path
#

and anything to do with linq is a) slow and b) generates a lot of garbage

nova ridge
#

Damnit

#

Then, I'll have to either remake the method myself or search another way to do it

nova ridge
#

So, came up with this

private string tw;
private string[] _currentActive;

private void Update()
{            
    for(int i = 0; i < _activeTweens.Count; i++)
    {
        tw = _currentActive[i];
        IPTween tween = _activeTweens[tw];


        tween.Update();


        if(tween.WasKilled)
        {
            RemoveTween(tw);
        }
        if(tween.IsComplete)
        {
            tween.onComplete?.Invoke();

            RemoveTween(tw);
        }
    }
}

public void AddTween<T>(IPTween tween)
{
    TwCount ++;

    if(LogLevel > 0)Debug.Log($"Created tween: {tween.Identifier}");

    _activeTweens[tween.Identifier] = tween;

    _currentActive = null;
    _activeTweens.Keys.CopyTo(_currentActive, 0);
}
drowsy lance
nova ridge
#

By removing all the Linq methods, and making it rely just on Dictionaries base methods, it should be faster, no?

upbeat path
#

I don't see the need for _currentActive at all, why not just itterate through the dictionary?

#

I'm not even sure why you use a dictionary instead of a List based on that code

nova ridge
#

The dictionary contains an string as an ID and the proper tween

#

And since you cant iterate with Index for dictionaries, I have a helper array to do so

upbeat path
#

but why? do you access the dictionay other than here?

#

itterate with foreach

nova ridge
#

I am modifiying the dictionary while I iterate throught it

upbeat path
#

again why dictionary?

nova ridge
#

I cant use foreach, it throws errors if the origin collection is modified

upbeat path
#

why do you need a Key

nova ridge
#

I do access it to check non repeated tweens get added

#

Like, trying to tween the same object's property at the same time

#

And with a Dictionary I am completely sure that it does not contain multiple instances.

#

The other option would be creating a List and checking it every time I add a tween, but this seemed more intuitive, I dont really know which option is better

upbeat path
#

Ok. what I would do is forget the array.
foreach on the Dictionary and make a List of those Tweens to remove
after the foreach, loop on the List to remove them from the Dict

nova ridge
#

Thats, like

#

The same way I made it, no?

upbeat path
#

no

nova ridge
#

Using a List instead of an Array

upbeat path
#

not at all, use a List to hold the Tweens to Remove not all of them

nova ridge
#

Oh, I see

#

Let me a sec then

regal lava
#

I'm assuming the problem stems from resizing this array if that's what you're doing cause that's a lot of tweens to be remaking one for. List/Dictionary sounds like the idea

#

Hashset even

#

Otherwise create a buffer size for the array and only extend it when it exceeds a few hundred

nova ridge
#

I just discovered that Hashset exist in C#

#

XD

regal lava
#

You can iterate over it too. It's really good

#

Order not guaranteed though

nova ridge
#

Ohh, that sounds nice

#

Do you know how performant is it?

drifting solstice
#

performant enough to be in the standard library

regal lava
#

usually it's just 0(1) like any other hashset

drifting solstice
regal lava
#

Θ

drifting solstice
#

that's a different metric

regal lava
#

I think it's still Θ(1) tho lol

#

average case

drifting solstice
#

but there's no metric that uses zero, afaik
best case is capital greek omega
average case is capital greek theta
worst case is capital latin o

drifting solstice
nova ridge
#

Alright! Remade that piece of code and it works like a charm!

#

Reduced a bit the execution time

#

Also, is there any way I can do something like this withouth relying on local variables?

#

The alocation is taking a significant amount of time

drifting solstice
#

yeah why not just use the methods directly

#

you could just cast instead of the extra variable, but im not seeing why you would need this method to begin with

#

it's not very generic since you're hardcoding each case anyways

nova ridge
#

Oh, makes sense

#

XD

drifting solstice
#

generics are for treating different types in the same way
this isn't a usecase for generics

upbeat path
#

And all that boxing and unboxing, horrible

#

@nova ridge Not wishing to be rude but for someone posting in #archived-code-advanced you seem to be lacking a lot of knowledge of C# internals

nova ridge
#

I am using the individual lerps after all xd

nova ridge
#

Since my initial thoughs were for optimization I guessed this was the place

upbeat path
drifting solstice
#

do you really need optimization here? computers are fast, and what's more important here is readablity and maintainability

upbeat path
upbeat path
#

definitely read up on boxing and unboxing

nova ridge
#

I rather be corrected than believe to be in the right way

nova ridge
nova ridge
#

So in extreme cases it may be needed

drifting solstice
#

don't optimize because it "may" be needed, do profiling to see if it's actually needed or not

#

otherwise you're just adding more work for premature optimizations

#

in all likelyhood a single if-else tree with 2 allocations and 2 casts, while ugly, is not a bottleneck

nova ridge
#

Im using 2 allocations per tick per tween, so It slows the whole thing down quite a bit

drifting solstice
#

2 allocations is not much

#

have you profiled it to actually verify that it's the bottleneck? (although i mean those allocations can be removed anyways by just not using this method)

nova ridge
#

Yeah, thats why I am saying so

nova ridge
#

Alright, done it! Didnt get that much difference but Its fine regardless

#

Btw, I have been coding for almost a decade now, but I have never needed to use complex/advanced techniques, is there any way where I can fully learn all those?

regal lava
#

Don't use arrays ;)

nova ridge
#

Or some of them, out of pure curiosity tbh

nova ridge
#

I read somewhere taht they were faster than regular list, so, I said to myself why not

upbeat path
#

The C# Docs are a good place to start

regal lava
#

I guess a little more overhead, but doubt it matters that much today

nova ridge
untold moth
slate spoke
#

This code is meant to read a .parquet from the StreamingAssets folder on both android and desktop, but it's only working on desktop, even though I'm using BetterStreamingAssets. What's wrong with my implementation?

thorn flintBOT
slate spoke
#

oh I guess you can't expand it cuz you're on mobile, oof

untold moth
#

Yes. It displays as a downloadable file.

slate spoke
untold moth
#

The code seems to be pretty straightforward. I don't know much about the third party libraries that you're using, but it's likely an issue with them. You'll need to check their docs or maybe contact their support.

#

It seems like better streaming assets is open source, so you should be able to debug it. Start with stepping through the code and seeing if the stream is opening the correct file and contains any data.

slate spoke
untold moth
dapper cave
#

has anyone used gxash-csharp? i see it uses hardware intrisincs and those aren't available in 2022

untold moth
dapper cave
untold moth
#

Oh, gxhash, not gxash. I see.

untold moth
dapper cave
untold moth
dapper cave
untold moth
#

That could just be an issue with the ide. Are there actual compile errors in unity console?

#

I'd assume that the issue is with dotnet version. The intrinsics class seems to only be compatible with Core 3.0, Core 3.1, 5, 6, 7, 8, 9, while unity doesn't support any of these yet.

#

If you find a C++ library for the hash, it should probably work

slate spoke
untold moth
slate spoke
untold moth
#

If you can check the device storage and see where the streaming assets files go on it and compare with the file path from the debugger, you might figure something out.

slate spoke
frigid pasture
#

hello guys, I'm trying to learn ml agents so that i can import the "brain" into a real life robot, its my second ever ml agents script, would you guys be able to review the code and tell me if there are things that i can improve about it ?, ill add all the details when i send the code (model, what does it do etc..)

#

(if im in the wrong chat topic could you also please redirect me to the correct one)

#

at the moment i feel like its very inefficient in how it works...

untold moth
frigid pasture
#

oh okay thanks

untold moth
#

Unless it's not specifically ml related question

slate spoke
frigid pasture
#

i mean its kinda an everything question because i just started using unity and the fusion360 models are also giving me alot of lag hmmm

#

thanks eitherway, ill go in that chat

untold moth
upbeat path
scenic forge
# slate spoke I'm working on a game for Quest 3 standalone that loads in a local .parquet data...

You also need to profile what exactly is causing the frame skips. If it's IO, you can use async which won't block main thread; if it's CPU code that doesn't have to run on the main thread like expensive computation, you can move that to a different thread; if it's code that has to be run on main thread like creating the game objects, then you can spread out the workload over multiple frames.
Always profile first to understand the problem before optimizing.

stoic otter
#

does anyone has here problems with the scrollview?
the strange thing is it worked on the xbox controller i did nothing with the component and its suddently broken.
not the only time the scroll view suddeltly break on me.
Do you guys also experience this?

stoic otter
#

aa sorry wrong channel

shell horizon
#

Does anyone know if disposing like this needs to be completed in the same frame or if it can be allowed to finish on its own?
JobHandle meshTrigsDisposeHandle = meshTrigs.Dispose(vertexCompileHandle);

#

Couldn't find anything online or in the documentation

sly grove
#

You should dispose the handle after the job is done

shell horizon
#

What do you mean by dispose the handle?

#

I'm asking whether I need to complete that job immediately or if I can just allow it to complete on its own time

sly grove
shell horizon
#

I'm using the dispose overload that schedules a job to dispose instead of disposing immediately

#

But i'll ask there thanks

novel cairn
#

Can anyone help explain this, My stats window shows my CPU is causing far more latency, But my profiler is showing that GFX.WaitForPresentGFXThread is costing the most which typically means the CPU is waiting on GPU to finish, Which one is causing the bottleneck?

sage radish
dusty wigeon
loud flame
#

Hey there! I'm trying to add mod support for my game. I'd like to allow the user to pretty much do whatever modification they want to the game including custom code.

I first thought about a manifest approach with a json file to store the metadata of the mod and then other json files to describe all the new assets. But I don't think it'd work out well with custom code.

On the other hand, there is Harmony that would bring a full control to modders over the game BUT it's also very dependent on the code itself (Update 1.6 of Stardew Valley broke a bunch of mods)

Is there any alternative I might have missed?

sly grove
granite gazelle
#

Yo i need help i have 2 triggers one for coke and one for cake and i have 4 ui text 1 bro before and after one mom before and after so i want to make the mom before disable and after enable if it detects cake trigger in the console and if it detects coke trigger do the same with bro

#

so how do i do it

untold moth
granite gazelle
#

NV,

#

Nvm

upbeat path
#

<@&502884371011731486> Spam

trail maple
#

UnityException: Transform child out of bounds
UnitSelectionManager.TriggerSelectionIndicator (UnityEngine.GameObject unit, System.Boolean isVisible) (at Assets/UnitSelectionManager.cs:128)
UnitSelectionManager.SelectByClicking (UnityEngine.GameObject unit) (at Assets/UnitSelectionManager.cs:117)
UnitSelectionManager.Update () (at Assets/UnitSelectionManager.cs:53)

upbeat path
trail maple
#

i think the code was to advanced so i moved it up

upbeat path
trail maple
#

oh no

trail maple
drifting solstice
#

yikes, no

trail maple
#

please bro just help me I'm dumb as hell just help

trail maple
drifting solstice
#

have you even tried googling the error

trail maple
#

yea and chatgting and copiloting

drifting solstice
#

yeah, avoid the latter 2

#

what did you gather from googling?

trail maple
#

yea like cheching if i have assigned the right child

drifting solstice
#

the stacktrace also points you to the exact line where it's happening
Assets/UnitSelectionManager.cs:128

unit.transform.GetChild(0).gameObject.SetActive(isVisible);
so unit doesn't have any children

#

that's all

trail maple
#

but it does

drifting solstice
#

then you're probably looking at the wrong one

trail maple
upbeat path
#

and how do you know that that is the Unit being used in the code? Did you check?

trail maple
#

yea

trail maple
#

if you want to check

drifting solstice
#

do you have the layermask set up correctly?

trail maple
#

think so yea

drifting solstice
#

have you tried debugging to see what gameobject is being detected at all?

drifting solstice
trail maple
#

yea like wait let me send you something

drifting solstice
trail maple
#

it is this one

upbeat path
trail maple
#

the moment i click on him there an error

#

but it has a child

drifting solstice
#

is the raycast picking that up though?

#

how do you know it isn't, say, picking up that indicator

trail maple
#

yea it works everthing does but when i click on Unit it breaks

drifting solstice
#

so that means not everything works

#

again, maybe actually debug

trail maple
#

ok

drifting solstice
#

try logging out unit.name and unit.transform.childCount

trail maple
#

what does that mean🦧

drifting solstice
#

Debug.Log

#

those values, right after the raycast

upbeat path
#

dont forget unit.GetInstanceId()

trail maple
#

ok i did

#

but it debugs

#

until like i want to do it the on the second or third

#

then it breaks

drifting solstice
#

ok, how so

#

"it breaks" doesn't give us any usable info

#

look at the logs

#

are they correct

trail maple
#

how do i send a video

#

though i link so that i can shwo you

#

or can i call you and screenshare

drifting solstice
#

no thanks

#

maybe answer my question first

trail maple
#

bro like i click and then the error comes up

drifting solstice
#

did you put the logs before the GetChild?

trail maple
#

yep

#

😤

#

jk

drifting solstice
#

are you getting the logs before the error

trail maple
#

yep

drifting solstice
#

ok, read the logs

trail maple
#

bro i just put the log to read sigma

drifting solstice
#

are they the results you expect

trail maple
#

yea but it still breaks

drifting solstice
#

and it's showing transform.childCount as 1?

trail maple
#

yirp

hushed fable
#

Since this is probably going to take a while and has nothing advanced about it, let's move this back to #💻┃code-beginner