#archived-code-advanced

1 messages · Page 22 of 1

jolly token
#

Much smaller than single texture atlas

#

So you don't really have to worry about having them on memory
What you can worry about is GC if you let them unreferenced

sterile snow
#

It probably matters a lot less than my mind assumed it would be

#

But aside from the character and stage that were selected by the player, I imagine it'd be a good idea to get these instances cleanly gotten rid of

#

At the very least tbh

jolly token
sterile snow
#

Fair enough, least I got some advice on the matter. Much appreciated.

jolly token
#

Okay I reduced it to tolerable level 😌

undone coral
#

this is fine

#

if you feel more comfortable describing this stuff in code than in the editor - i would have done it in the editor - well this is #archived-code-advanced , you are capable, you can do that

sterile snow
#

Well, good to know it's fine!

muted ridge
#

I have, and im using windows 10. the dll works fine is visual studio. im just trying to use it with unity. the available assets for kinect are rare and very old.

#

do u have one that uses unity? (sry for the late answer)

young wraith
#

Hi anyone

#

I'm making a clean up game

#

but line 147-150 makes the game slow

#

How can I enhance that line of code

flint sage
#

Do one getpixels call instead of so many individual ones

#

But the real winner is using a shader and graphics.blit

undone coral
#

you can't just copy and paste that one DLL

#

i think you'll get a little more experienced with this stuff and it will be easier

muted ridge
undone coral
#

it's not going to be that one DLL

#

the DLL itself has references to other DLLs, and the runtime tries to find those via a variety of strategies

#

it's telling you it can't find something

#

i think if you configured the error messages correctly, it would tell you what that is

#

it may already be telling you in the editor

#

that said, there is an official, modern Azure Kinect device, and a modern nuget package, which may be easier for you to use

muted ridge
#

this is the error im getting

muted ridge
undone coral
#

it might be easier to copy the entire SDK directory into your Assets/ folder for now though

#

that might Just Work

#

you should also use .net framework 4 as your ... whatever it's called

#

i hardly remember anymore, but you will change it from .net standard 2 in your player settings

muted ridge
#

thanks a lot, ill try it out when i got time !

exotic gull
#

Trying to use Newtonsoft Json in my project. Any idea what's causing this? ```cs
class Control
{
[JsonProperty("look_x")]
public float look_x { get; set; }
[JsonProperty("look_y")]
public float look_y { get; set; }
[JsonProperty("jump")]
public bool jump { get; set; }
[JsonProperty("arm_left")]
public bool arm_left { get; set; }
[JsonProperty("arm_right")]
public bool arm_right { get; set; }
[JsonProperty("forward")]
public bool forward { get; set; }
[JsonProperty("backward")]
public bool backward { get; set; }
[JsonProperty("left")]
public bool left { get; set; }
[JsonProperty("right")]
public bool right { get; set; }
[JsonProperty("dead")]
public bool dead { get; set; }
[JsonProperty("reload")]
public bool reload { get; set; }
}

class HFFInput
{
public static Control hffControl;

public static void init()
{
    hffControl = new Control();
}

public static void unpackJson(string json)
{
    hffControl = JsonConvert.DeserializeObject<Control>(json);
}

}```

maiden turtle
exotic gull
#

Working with the BepInEx plugin injector to inject code into a game at runtime (modding). To the best of my knowledge, the game uses Unity 2017. I've included the Newtonsoft Json and System.Numerics dlls in the plugins folder to be injected along with my code.

#

And in case you're wondering, the mod is really only applicable in a singleplayer setting, and a lot of the community is supportive of the development of this mod. (The only reason I say this is because the last time I asked for modding help here, people asked to make sure I wasn't doing so for nefarious reasons before they provided help)

regal glade
#

i'm trying to figure out multi-threading, especially using Parallel.For from System.Threading.Tasks. i just wanted to ask since it's running way worse than a normal for loop, and before I waste 20 hours reading, is this the way to do it in Unity, or does Unity prefer some other method for running a Parallel.For loop? I'm seeing some stuff about ParallelFor jobs but not sure that's what I should be looking at.

compact ingot
regal glade
#

i'm trying to learn it so i'm not sure i'm doing it right, and the for loops i'm attempting it on are long and complicated, but it simply runs way worse when i run it so probably something is not done right.

compact ingot
regal glade
#

simply checking the frame rate in both the editor and in a build, it drops from 120-300 fps to 80-120 fps

compact ingot
#

so you run those tasks every frame?

regal glade
#

yes

compact ingot
#

well that’s not going to be performant indeed

#

you should run worker tasks independent of the update loop

regal glade
#

why is it so bad to run a Parallel in the update? wouldn't you do something similar for multi-threading pathfinding for example?

compact ingot
#

let them finish whenever they do and use the result when they are done, launching new tasks every frame is wasteful

sly grove
#

what exactly are you trying to multi-thread?

regal glade
#

oh boy. well, i've created a 3D tile system where each tile is represented by a 3D array of Tiles, and each frame where the camera moves I run a for loop to iterate through the visible tiles and create a "slice" of the world represented by values in a Color32 array that I then send to a shader via a Texture3D

#

i say 3D but this is still very much 2D

compact ingot
regal glade
#

so i have a 3 for loop deep nested loop (x, y, z) that does some checks to look for walls, doors, etc to determine render states

#

it runs fine even on old CPUs but it's still by far my heaviest process so I wanted to attempt to multi-thread it if possible

compact ingot
regal glade
#

yea maybe

#

maybe i should look at this job system first

compact ingot
#

the job system will guide you a bit more

#

but you might end up figuring out that true performance improvement would require very specific data structure that drives the computation and parallelization, which ultimately leads to data oriented programming/ dots

regal glade
#

yea just gotta figure out what that is first 😂 sorry multi-threading is completely new to me

compact ingot
regal glade
#

been reading all day but still very confusing

compact ingot
regal glade
#

just need to find some good resources that isn't MS docs

compact ingot
#

How theoretical/generic do you want it to be?

regal glade
#

i don't mind as long as it's not MS docs. MS docs only works for people who already know most of it, it's like reading math on wikipedia.

#

any resources are good resources, can always learn bits and pieces here and there

#

if you have any recommendations i am all ears

compact ingot
#

in textbooks that are written to accompany such a course this same explain would also occur

#

The keywords to look for are concurrent and parallel programming

regal glade
#

i don't really like going through courses but i'll consider it, thanks for the tip

jade jackal
#

they are extremely hard to navigate unless you already know where everything is

tribal pivot
regal glade
#

@tribal pivot i did profile it and the function takes like 5-6ms, and it's iterating through 3 axes of tiles in a matrix so it might be like 80*60*50 entries. like i said it runs ok at the moment but i wanted to look into multithreading it, it just felt like it made sense to offload some of the 240 000 loops to other cores

#

because i am also going to add more on top later

#

i say "matrix" but it's a 3D array

#

all the iterations of the for loop are independent really so i don't need them to return in any specific order, i just don't know why it runs badly yet ArithShrug

#

maybe they're fighting over access or something, or the parallel overhead is actually simply heavier than the loop

#

that's what im trying to find out

#

not to mention thread safety

north thorn
#

hey, when using the xr rig, is there a way of getting possibly position (vec3) and rotation (qt) for each eye? i know that when using ovr, the eyes were already there named as left and right camera anchor. here with xri i get just the center camera and for my project i kinda need both right and left ones.. help pls

plain gate
#

Could anyone help me converting a counting sort algorithm to be in place?

sly grove
compact ingot
plain gate
plain gate
# compact ingot Those two

But if it is not in place you would need 3 arrays. The input array, the count array, and the temp output array.

compact ingot
plain gate
#

correct this is not "true" in place but my count array is very small and doesn't really impact.

compact ingot
#

sure, but you asked for in-place and it sounded like a theoretical question which generally has little to do with what matters in practice

sly grove
#

this is not Unity related

young wraith
long ivy
hollow socket
#

I can't tell if this goes in advanced or beginner but I'm struggling to find a way to find the difference in the way an object is facing to an object

#

like a number of how far off the rotation is to facing the object

brisk pasture
#

the difference in what unit

hollow socket
#

degrees

brisk pasture
#

Vector3.Angle should work

#

compare your transform.Forward with a vector you create by subtracting position from the target object position

hollow socket
#

Ok

#

Thanks

brisk pasture
#

the example is exactly what you are trying to do

hollow socket
#

wow

brisk pasture
#

if the angle should only be around the Y axis you can use Vector3.SignedAngle the exact same way too

#

jut pass it Vector3.up for its 3rd arg

#

this will also let you know which direction the angle differs in as well

hollow socket
#

Thanks

young wraith
compact ingot
young wraith
#

When I try to remove the code Color pixelDirtMask = _templateDirtMask.GetPixel(pixelXOffset + x, pixelYOffset + y);

compact ingot
#

you should also not get/set individual pixels

#

it says so in the docs

young wraith
compact ingot
#

you'd load the whole texture into a buffer, and process the changes in that buffer, or use the raw data to do the same

regal glade
#

I've managed to get pixel getting and setting running pretty well every frame, but it depends on the size of the texture. The best method I have found so far is using get and setpixels32 and then adjusting the color32 array

compact ingot
#

^this (multi pixel methods) also works

#

but editing textures like that is very inefficient regardless

#

what would be 100x better is doing all this with a render texture

#

or a compute shader

young wraith
young wraith
compact ingot
#

do you need pixel accurate info on what is dirt and what is not?

#

typically you'd have one datastructure that holds the info on what has been cleaned (a low resolution texture or plain array) and another one that handles the display of the progress in a nice way

young wraith
compact ingot
#

--> screen pixel accurate <-- is the keyword here

young wraith
regal glade
#

Is this 2d or 3d

young wraith
regal glade
#

Then even if you have a 1080p resolution a 2d array should be fine to determine what's on the screen. You can make the game logic alter the array contents and only draw it every frame with no get calls.

#

Alternatively store the status of the dirt in a color32 array only and alter that

#

Then you can just do setpixels32 directly

young wraith
#

Thank you for ur inputs I love u all

regal glade
#

Since the screen has 2 axis and the color32 array is 1d you have to do something like "x + (y * xSize)" to access it right in a nested for loop if that makes sense

#

On phone

young wraith
copper steeple
#

Hello! idk if this is a code-advanced question but i didn't find anything useful in google so yeah. Anyway, the question is: How can i create custom properties on the inspector using fieldInfo?


            foreach (FieldInfo fieldInfo in myCustomType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                EditorGUILayout.PropertyField(fieldInfo/*do magic with fieldInfo?*/)  ;
            }
flint sage
#

Use SerializedProperties instead of fieldinfo

copper steeple
#

but how? idk how to, all i can get is fieldInfo or propertyInfo

#

in fact, that's the main problem

flint sage
#

CustomEditor?

#

this.serializedObject.FindProperty

copper steeple
#

i can't, i don't have an instance of the object i want to get the fields of

#

and please tag me so i can respond faster

flint sage
copper steeple
#

i have a custom class that contains information an entity should have: property. Let's say Shield. A shield property should have : maxShield, shieldSprite, ShieldColor etc. I want to tweak the values of the shield property for each prefab; i also want to do that in one place: the entityBuilder AND i want to make it generic so i don't have to change the code each time i add a different property. That's why i'm searching for all types that inherit from the abstract Property class. For each iteration, i want to get the property fields and draw them in my entityBuilder so i can edit and store the data

#

maybe i'm doing it wrong, but at this point i just wan't to know if my solution is even possible

#

bellow should be a SaveProperty Button

modern storm
#

Is there a way to force an update of a transform's position and rotation so it is reflected in the hierarchy immediately?

young wraith
winter yacht
regal glade
#

Since the screen is both x and y but you are using a 2d color array you need to multiply the y value by the maximum size of the x axis, so 1920 for a 1080p resolution

#

So when y goes up to 1 we add a full loop of x to the index

modern storm
#

@winter yacht I use an active ragdoll and when I enable the gameobject I play an animation, the animation rig's transform are immediatly set to the right positions, but the active ragdoll's rig takes an extra frame to set itself even though I go through all the transforms to set them to match the animation rig's position and rotations.

regal glade
#

This is within a nested for loop

winter yacht
#

Basically hide the first frame somehow.

modern storm
#

@winter yacht If I Debug.Break right after enabling the object, starting the animation and setting the transforms, I see the transforms of the ragdoll are not at the positions I set them. The renderer is enabled.

#

Yes I do this already but it causes other issues. Those ragdolls replace entities rendered with DrawMeshInstancedIndirect when I need them to interact with physics. I was hoping to find a way to get them ready to receive a beat up on the same frame I enabled them.

#

I was hoping to find something like Animator.Update() for transforms to force an update

#

Does anyone know when changes to a transform is updated in the hierarchy? Is it during FixedUpdate ?

compact ingot
modern storm
#

@compact ingot This shows the problem well, In this image the green rig are the transforms used by my active ragdoll, the red one represents the animator's rig. This screenshot is taken just after I enable the gameobject, play an animation with animator.Play() and run through all the transforms of the green rig and set their position and rotation to match the animation rig (red). Then I did Debug.Break to take a shot.

#

Somehow the animator manages to set the transform of it's rig on the same frame the animation starts playing but the changes to the green rig are not reflected untill the next frame

pale pier
#

Anyone have any idea how this audio mixer group selection UI is made? I want to make UI like it to be able to nest items inside each other

winter yacht
modern storm
#

@winter yacht yes. The position of the green rig at that moment is the position it was at when the gameobject was previously disabled.

#

as in the animation that was playing at that time

#

Since I'm replacing entities with the dolls, I need it to be ready on the frame it's enabled. Thats why im trying to figure out how to force the transform update

#

somehow the animator manages to force that update

lament salmon
#

might help/be related

modern storm
#

I will check it out ty

lament salmon
modern storm
#

That's worth a try!

modern storm
#

@lament salmon unfortunatly that doesnt work 😦

reef lance
#

Anyone familiar with CIL, can I use call instruction but pass a lambda instead of a static method and if yes how?

twin vector
#

by looking at the IL it looks like call is used for methods
and lambdas are used with callvirt

#

You could generate a display class and call that if u really want calls but that might be counter to what you'd want if you're looking at CIL

flint sage
#

If you're generating IL yourself then iirc you can but I doubt you can coerce the compiler to generate it for you

hot gale
#

Hey so, I'm wondering if something like this is possible. I have a Height Map and a Texture Map for a Sphere that are mapped Cylindrically

#

Is there any way to project the heightmap onto a sphere and then apply the texture so that I can create a planet type object?

flint sage
#

Sure it's just math

hot gale
#

Yeah, I meant more with Unity's built in stuff.

light falcon
#

Hi, quick question; can you save json in a custom file type? Some games have save games called 'Savegame.data' or some other custom extension. I would like to know if it's as easy as changing the file extension

flint sage
#

Yeah sure

#

Just read it as text and it doesn't matter what the extension is

devout hare
#

Yes, you can name the file whatever you want. The file extension isn't the same as file type.

flint sage
#

Extensions don't really mean anything, it just helps the OS to decide what application to open

jolly token
light falcon
#

Thanks folks!

safe vapor
#

What would be a good way to go about making a "terrain smoothing" brush? I'm making an in-game level editor. I want to make something that has the same basic behavior as the Unity Editor terrain smoothing brush (I already have all the other editor brushes implemented).

#

anyway, I guess one good way is to make a loop that starts on the outside of the selection circle and goes in a spiral. For each vertex, it raises or lowers the loop iterated vertex in whatever direction the average height of those 5 vertices is. That's probably the best way but to make it go in a circular spiral pattern, that would involve some complicated trig that might introduce rounding bugs

#

If there was a way to use the editor's actual smooth height function, that would be great but I haven't found it, if its possible

undone coral
safe vapor
#

oh is that all it does? Wow ok I was trying to make it more complicated than it needs to be

atomic void
#

Hello,

What do I do when I have big list of positions and I want to draw instanced meshes on these points?

#

Can I just send a Vector3 list for positions to the gpu?

#

I am currently sending transform matrices and using Graphics.DrawMeshInstanced

sly grove
#

DrawMeshInstanced only takes matrices iirc

atomic void
#

Yes, thats the case

#

I know what transform matrices do
DrawMeshInstanced didnt let me have more than 1024 matrices

sly grove
#

correct 1023 at a time

#

You have to batch them

atomic void
#

And I was thinking that it is not efficient sending any more information other than positions to the gpu

#

Because rotations and scale dont change in my case

sly grove
#

If you want to get more efficient you'll want to look into DrawMeshInstancedIndirect

#

In which case the position data will come from a compute buffer

atomic void
#

Will I be able to have more than 1024 with a standard shader?

#

Now that I think, I'll hit the materials input buffer limit

sly grove
#

If you use DrawMeshInstancedIndirect you'll need your own shader which reads position data from your compute buffer

atomic void
#

If that 1024 is because of the materials input buffer size limit

sly grove
#

This is a really good guide on it:
https://toqoz.fyi/thousands-of-meshes.html

atomic void
#

@sly grove allright thanks

kind sigil
#

I want to create a custom attribute [RadiusGizmo] that I can slap on any float field and as a result I want it to draw a circle with the given radius as a gizmo in the scene view around the selected game object. Where do I start?

dapper nest
#

I cannot wrap my head around how to implement this. I'm trying to implement movement so that when the player is on a slope that is "too steep", the input direction should be translated so that it does not move up it. As if you set the movement direction into the slope (even with 0 at Y axis), the physics system will still push it up (unless it is a 90 degree wall). Any ideas how to implement it so that the movement on a steep slope is the same as if it were a 90 degree wall? I made a very artistic visual representation in case I can't explain it well enough in words

#

Here is the current logic for sloped movement, but because I want my air acceleration high, it just shoots up on steep slopes

private void SlopeMovement()
        {
            // Calculate desired velocity based on direction
            Vector3 desiredVelocity = m_desiredDirection * m_airSettings.MaxSpeed;
            desiredVelocity = Vector3.ProjectOnPlane(desiredVelocity, Vector3.up);

            // Determine if we should accelerate or decelerate
            float speedChange = (m_desiredDirection == Vector3.zero) ? m_airSettings.Deceleration : m_airSettings.Acceleration;

            // Find new velocity and apply it
            Vector3 newVelocity = Vector3.MoveTowards(Motor.Velocity, desiredVelocity, speedChange);
            newVelocity.y = Motor.VerticalSpeed;
            Motor.SetVelocity(newVelocity);
        }
#

sorry if this doesn't go under "advanced" code, but no one seems to have the answer elsewhere 😅

silver pendant
#

How about adding an invisible 90° wall? It's kinda dumb but it could be an easy solution.

dapper nest
#

And collide with the air every time there is a steep slope... ?

#

I am asking here because there has to be some way to calculate it, not ruin the game experience

frosty violet
#

Hello everybody. Does anyone know how I can convert a value from a linear range [1, 0] to a value in a logarithmic range [1, 0]? thank you

forest isle
dapper nest
flint wraith
flint wraith
livid kraken
# dapper nest This really does not solve anything though. As for limiting velocity added to y,...

https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131 with this asset being now free I can not recomend it enough. Look at the code even for learning purposes.

Get the Kinematic Character Controller package from Philippe St-Amand and speed up your game development process. Find this & other Physics options on the Unity Asset Store.

forest isle
frosty violet
flint wraith
frosty violet
flint wraith
#

Oh you were doing just that thing?

#

Hahahahaha

frosty violet
dapper nest
wet burrow
#

Any of you guys know how to import a .GIF file as texture assets in runtime? I want a way to play them in-game, but I want to be able to load them from a file that's already on the user's device. I found one method that seems to only be set up for downloading GIFs from a URL, and another that requires System.Drawing.Imaging which seems to be incompatible with my project.

proven venture
#

if you want to write your own you can use an imagemagick wrapper and get the raw pixel data for each gif frame and call LoadRawTextureData

#

else just google one

ember peak
#

how to export to android?

wet burrow
wet burrow
# ember peak how to export to android?

go to build settings and set the target to Android. Make sure you've downloaded the necessary NDK and JDK, and that you've enabled USB debugging on your device.

misty glade
#

I have a client-server game that is a unity client along with a C# console app (containerized and deployed in Azure so I can eventually scale it). I've been a little bit lazy with some of the networking messages, opting to occasionally send the entire player model back and forth instead of cherry picking data and merging it on both ends.

As development has progressed, I'm finding that the model is getting larger - it's about 1kb - and many normal game operations send the model back and forth.

How should I plan for load here? Where do I spend my efforts? It's pretty time consuming to pick out only the data I need and re-assemble it on both ends, but I'm starting to worry that I won't be able to scale unless I cut down on the bandwidth. Should I base my efforts on some sort of "normal" kb/sec average and use that to guide my efforts?

Thanks for your thoughts. Screenshot is of console app running locally while I click around the app.

#

It's probably on the order of like 5kb/minute for normal gameplay..? But I was hoping that my server would be able to scale to several thousand concurrents or more - 5MB/minute seems low, yeah?

undone coral
misty glade
#

In terms of total server throughput - what kind of numbers do you think I should start thinking about it? I'm planning to add quite a few more features and I find just sending the entire player model back and forth is convenient

#

If I were able to get 10k concurrent users (I mean, first of all, hooray, right?) that'd be around 50MB/min - I feel like that'd be pretty dangerous

#

Spikes could easily be 10MB/sec

undone coral
misty glade
#

I'll keep an eye on that. I hadn't really thought that'd be a bottleneck. I was always assuming it would be bandwidth - which feels harder to solve than cpu/ram/disk issues

undone coral
#

on public clouds, bandwidth is always bad. you'll have to contact them directly with your support account to get advice on specifically which instance where has good bandwidth

#

for example the outbound bandwidth of a M6 instance on AWS is about 25MB/s

#

last i measured

#

which is quite low.

#

10MB/s is fine

misty glade
#

I don't speak AWS instance sizing 🙂 But my azure container instances are tiny, but I have no idea what kind of networking costs/throughput I get with them

undone coral
#

hmm

#

well it's going to be the RAM that stops you from getting to even 100 concurrents

#

although, 100 concurrents is like a 150,000 DAU game

misty glade
#

I think I have to pay for all these metrics

#

maybe not

#

Anyway, I'm probably just wasting time.. I should get back to the game dev. (btw, beta launch in tier 3 markets scheduled for nov 15 woohoo)

undone coral
#

for spellsource i have a benchmarking system with a dummy client

#

to measure how much RAM each user takes

#

yeah

misty glade
#

I spent the whole weekend ripping out the networking library and replacing it with a different/(better?) one

undone coral
#

no that stuff is a little low yield

misty glade
#

I was showstopped by not having nat punchthrough support on the older one

#

you ever work on something really gnarly for like 72 hours and then magically it works and it's done and you're kind of in a daze after? that's me

#

(including a 2+ hour support call with ms azure support.. which was awful, they literally couldn't figure out Zoom so they all had the wrong audio devices and were playing my voice through their speakers with horrible feedback/echo)

undone coral
#

lol

misty glade
#

"dude trust me you aren't using your headset I can hear myself clearly"

#

memory usage seems....... really low

#

In broad terms - what's going to soak a lot of memory? Is it the overhead on connections? My game is pretty lightweight - I think an active user is gonna use something like 2-4kb

#

those are my container sizes - tiny

undone coral
#

nothing? is it just a relay essentially?

misty glade
#

virtually nothing.. there's no "world" per se, it's mostly just .. hm.. how do i describe it.. it's an idle game, so i track occasional things like currencies, speed, distance, but most of the calculation is done on the client

undone coral
#

i think it's probably fine then

#

sometimes there is a per-thread memory cost that is high on managed runtimes

misty glade
#

ie, we trust the client to calculate distance and taps and stuff, and then the client just says "ok i reached level 2, here's my player model" and I do some light validation on it and persist it, that's mostly it

undone coral
#

if you do not do thread-per-connection/thread-per-user you are fine

misty glade
#

Yeah, I don't ever send anything to all connected clients (aside from shutting down gracefully, which honestly doesn't count) 🙂

undone coral
#

the bandwidth willb e fine i think

misty glade
#

(battles are turn based battles so even the ProcessBattles() call is virtually empty - it just checks to see if it's any computers' turns and if so, takes those turns)

undone coral
misty glade
#

Yeah, but it's small

#

maybe a few hundred bytes

#

All of those dicts and lists contain objects with only a couple of fields, and the collections themselves will only have <10 items

#

I still have to figure out how I'm going to load test this application.. I suppose I'm going to have to write some app that can fake a player for each module of the game and .. click around and stuff

undone coral
#

this is with 400 concurrents playing as quickly as possible

#

it's a way more complex game

misty glade
#

Do you have your tests in your CI/CD pipeline?

undone coral
#

yes everything is tested

misty glade
#

I probably ought to do that. That's one of my biggest gaps I think but... you know, indie things. (don't hate me)

undone coral
#

it makes more sense for me because randos were contributing

#

and can break things in surprising ways

misty glade
#

Yeah. I suspect I have a huge ass pile of unfun work once I start friends and family beta testing

oak sinew
#

hi there wanted to ask how can i make controls like these? i want my players to scatter inside that area like in this video
I've tried using navmesh and assigning random destinations but it isn't giving a scattering feel like in this video

glass anvil
#

the scattering is just them bumping into eachother

#

but maybe there is more to it than that have no idea where this is from.

white pecan
#

Does anyone know how I can get the IntPtr of an IEnumerator

brisk pasture
#

think you would need to go through GCHandle for that

#

var handle = GCHandle.Alloc(items);

#

then cast the handle to a IntPtr, and be sure to free the handle when you are done with it

#

think it has a ToIntPtr method on it as well

#

now i would question why, IEnumerator is not a regular collection of stuff in continuous memory you can easily pass off to something else or memory map

timber flame
#

What is the best common name for storage classes and persistent data? (save/load persistent data)
Also what about mapper/converter to map object to persistent data
For example there is a world object (voxel game) and I want to convert it to WorldPersistentData
WorldObjectToPersistentConverter?

   public class WorldObjectToPersistentConverter
    {
        public WorldPersistentData Convert(World world)
        {
            
        }
    }
    public class WorldPersistentToObjectConverter
    {
        public World Convert(WorldPersistentData worldData)
        {
            
        }
    }

A world consists of chunks and each chunk has voxels.
Also, copying data is time consuming. Is it better to have one data structure for logic and persistent data?

lament salmon
dapper cave
#

when you dispatch a compute shader, does it immediately start execution ?

pliant crest
#

shouldn't you be streaming in data

#

and streaming out data

#

assuming its works on same basis as any other 3d chunk loader

real plume
#

i have a somewhat general question, but i could post code if necessary: i'm running a tilemap game that has a separate tilemap for the water tiles, which are running a kind of cellular automata process to simulate fluidity. the code works well enough, and if there's not a lot else going on there's no issue. however, after a time, i start getting major cpu hits when other things happen during runtime like instantiation and destroying of gameobjects. my question is mainly if doing the water tilemap running calculations on where to move next update is the type of thing that would be worth trying to run on a separate thread, or if i should be looking at other optimizations first?

lament salmon
real plume
real plume
# real plume i've done that and it seems like the major fps spikes are from "animation", whic...

i think what is happening is that the water calculation process is hogging the main thread so when other things want to happen they have to wait. but i guess my other question would be is if this "animation" cpu usage looking like a spike would necessarily translate into that same spike occurring even if the calculations were magically done with zero cpu usage (just theoretically). if that were the case, i would need to look at reducing the animation, but if it weren't the case, then i could look into reducing the main thread load from that calculation process.

long ivy
#

you need to determine if it's animation or calculation that is causing your performance problem. How you optimize will go from there. If it's animation, a separate thread won't help because you can't interact with the tilemap outside the main thread

real plume
# long ivy you need to determine if it's animation or calculation that is causing your perf...

that's what i was thinking. and i understood that second statement somewhat lol (just watched a good video on the subject). do you have any suggestions as to how i might start diagnosing which is which? i guess this might require getting into specifics but are there any general techniques for helping to parse this? i only first opened the performance monitor thing yesterday so there's a lot about it i don't understand...

long ivy
real plume
real plume
dapper nest
timber flame
formal falcon
#

I'm making a game for a gamejam, and I've run into an implementation problem involving audio...
So there are two scenes, one scene is a 2D game where the camera renders to a render texture, and a scene where the game is being played (render texture on a TV model.)
The problem I'm facing is getting the audio to route from the 2D game to the "real life" scene in a way that audio from the 2D game seems like it's coming from the TV.
The obvious hack is to fade volume of the 2D game master mixer based on distance, but is there a more elegant way to achieve this?

#

The idea is that you can leave the 2D game on the TV playing if you want, and walking away from the TV changes the audio (volume, doppler, etc.)

ruby hare
#

Wnat to ask is there new feature other than asset bundle to help with dynamic content ?

brisk pasture
#

addressables

#

its built ontop of asset bundles but makes them a lot easier to use

#

also the scriptable build pipeline if you just need to make existing asset bundles more flexible

timber flame
#

I get this error when using message pack csharp serialization

FormatterNotRegisteredException: Bitzooma.MiniCity.Core.WorldPersistentData is not registered in resolver: MessagePack.Unity.UnityResolver

I have used Key() attribute and MessagePackObject for classes

  private static readonly MessagePackSerializerOptions MessagePackSerializerOptions = new(UnityResolver.Instance);

Unity 2021.3.6 .NetFramework + Mono
and if I use MessagePackSerializerOptions.Standard I get the error below

MessagePackDynamicObjectResolverException: can't find matched constructor. type:Bitzooma.MiniCity.Voxel

What does it mean? I should have ctor in data structures?!

flint sage
#

I don't have reference code anymore so can't give you concrete details

timber flame
flint sage
#

Could be but that's how I did it

timber flame
#

Thanks

#

and why the errors are different when I change the options

#

It worked

 [SerializationConstructor]
        public Voxel(byte id, byte rotationType)
        {
            Id = id;
            RotationType = rotationType;
            _flags = 0;
        }
undone coral
# formal falcon I'm making a game for a gamejam, and I've run into an implementation problem inv...

So there are two scenes
do you mean two scenes or two Scenes? it sounds like you have one Scene

audio to route from the 2D game to the "real life" scene in a way that audio from the 2D game seems like it's coming from the TV.
unfortunately you can only have 1 audio listener. my suggestion is to place the 2d game content right where the TV is, and hide it from the main camera using rendering layers. then it will all work idiomatically

formal falcon
undone coral
#

i say that because it wasn't clear from your language

#

if you meant scenes metaphorically, or a literal unity scene

#

i don't think the scaling will matter. as long you use a game object to achieve scaling and positioning whose local space is still "normal" coordinates for the 2d metaphorical scene

#

it should work well

formal falcon
undone coral
#

hmm

#

anyway that is my advice, i think your game sounds great

#

all the other solutions are more complicated. you could try duplicate the audio sources into the tv, at the right positions, which is a lot harder than moving the metaphorical 2d game scene

#

you can also ignore audio

#

which i think is what you are probably going to do

formal falcon
undone coral
#

really depends what the goals are. immersion? is it meant to be played in a browser? etc. etc.

undone coral
#

but i've been striking out lately with trying to get people to do good stuff

formal falcon
#

BUT, changing volume in the mixer based on distance would be more performant, just not as immersive. but it's a gamejam game so that's okay

undone coral
#

when it would take you all of 5 minutes to move the 2d game scene into the tv, and set up the camera render layers correctly

#

it's a game jam

#

you're talking about performance...

#

it's a built in render pipeline game right?

formal falcon
#

Yeah

scenic forge
#

I have a source generator project specific to the Unity project, I only want to source control the SG source but not the built SG dll. Is there a way to make Unity execute a command when opening the project so I can use it to build the SG project and copy the dll over (it has to happen early enough in the opening process otherwise I'm under the impression that SG wouldn't work) rather than having to tell people that clone the repo to "please build the SG project, copy the dll over, before opening the Unity project"?

undone coral
#

normally you could achieve this using an asset preprocessor, but it will always be glitchy to generate code which then modifies the player assemblies on launch

rain wolf
undone coral
#

i have never gained anything from generating sources at launch, and have gained a lot from checking it in, and i've been using source generators for years

#

that said, you probably mean a msbuild feature called Source Generators

#

and not something like protobufs

#

you should check in the DLL

scenic forge
rain wolf
scenic forge
#

I don't think it's ideal to check in the SG dll, it's really just artifact of the SG project and that should serve as the single source of truth

undone coral
#

yes but it might provide zero ROI

proven venture
#

InitializeOnLoadAttrib?

undone coral
#

to generate this on demand

#

what is the project?

scenic forge
#

If someone makes changes to the SG project but forgets to rebuild and commit the new dll, that's a mistake that will be pretty hard to spot.

#

They can get out of sync due to human error basically.

undone coral
undone coral
rain wolf
undone coral
#

and someone who lacks that knowledge, who can't modify e.g. protobuf files, will never need to think about source generation in either scenario

#

i don't know. unity is a build tool, it's not a Build Tool

#

i use gradle as my build tool, and i do have a single command for all source generation

#

it really comes down to what the project is

undone coral
#

and executes the generation step

#

i guarantee you that it will be really buggy

#

it will be running all the time

#

it will be hard to engineer it to detect changes, etc.

#

because you will be reinventing a build tool

#

you can try to use an asset importer class, but that is going to be

proven venture
#

then FileSystemWatcher and rebuild on change

undone coral
#

i will just say that i can tell you haven't done this before

#

it is not that simple

scenic forge
#

Ideally Unity would just support project reference so you can just reference the SG project like you normally do.

undone coral
#

well on the flip side, vendoring has a lot of benefits too

#

what is the project?

undone coral
#

i have a separate solution that, via a build tool, generates assembles that i check in

#

i do that because when an artist does need my repo, they will not comprehend any steps beyond "download a zip" and "open the project"

#

they're not going to understand git anyway

#

they're not going to be using this thing. they don't reall yhave a reason to be in unity, honestly.

#

so it's tricky

#

really comes down to what the project is

rain wolf
scenic forge
#

You can just modify the csproj straight in that hook, don't need to edit manually

rain wolf
undone coral
scenic forge
#

But the bigger problem remains that those changes won't affect actual building so it's pointless.

rain wolf
undone coral
#

you do not use them directly from unity

rain wolf
undone coral
#

you create a separate solution that is an ordinary dotnet solution

#

and use dotnet publish

#

and cp your build artifacts into unity

rain wolf
#

the consumer is who has to specify the files for the generator.

scenic forge
#

That's exactly the problem we are trying to solve, to make that process automatic instead of manual for every time SG is changed.

undone coral
#

unity isn't a Build Tool, it cannot know.

rain wolf
#

yeah, i'm not trying to make it one

undone coral
#

yeah

#

you definitely cannot modify Unity player code

#

using a source generator

#

is that what you are trying to do?

#

for code weaving?

rain wolf
#

getting the source generator imported works fine, but the source generator needs ot know where files live (and this is usually specified as AdditionalFiles in the CSProj)

#

nah

undone coral
#

okay

rain wolf
#

we are generating an enum for localization keys

undone coral
#

honestly i would ismply avoid using the feature

rain wolf
#

which works

undone coral
#

well

#

that is honestly kind of low ROI

#

this is a very very burdensome, buggy feature to use

#

for that

#

@scenic forge hasn't said what the projec tis

#

so i don't know

#

sorry i can't give better advice

rain wolf
#

cool

undone coral
#

you can just go and make the enum

#

the mistake would be obvious

#

nobody really fucks that up

#

and when they do it takes seconds to fix and is obvious

#

so i don't know

scenic forge
#

I mean it doesn't matter what the feature is, it's already determined SG is a good way to solve our problem, simply to make SG nicer to use than having to do all these manual labor of copying and syncing.

undone coral
#

besides, there are approaches to localization that obviate the need for that

rain wolf
#

pretty cool to hear that you work with devs that don't make mistakes.

undone coral
rain wolf
#

i make mistakes and have caused bugs

misty glade
#

I have something busted in my build, and I'm not sure how to fix it.

I recently refactored a script to rename it from ISGSceneManager to IsgSceneManager. Works fine, but now only on Android, I get these error messages in my build:

How 2 haz fix

undone coral
misty glade
#

(I've deleted the DDOL object, readded a new one, readded it)

undone coral
#

where you change it so that it doens't differ only in casing?

misty glade
#

What's the rename trick? To force unity to generate a new guid for it?

undone coral
#

try changing it back to ISGSceneManager

#

then rename to ISGSceneManager2

#

then rename it to IsgSceneManager

misty glade
#

IIRC unity refers to the script objects by a guid or something?

#

k

undone coral
#

refactor rename*

undone coral
misty glade
#

Yeah, no problem.. I was thinking of mucking with the meta files and making sure they're correct

undone coral
#

yeah

misty glade
#

Actually...... I can probably at least verify the problem is there by looking at the guids and making sure they line up

undone coral
#

gradle or bazel

#

they are good build tools to solve problems like these

#

otherwise you can share what you are using the source generator feature for, maybe we can brainstorm an alternative

scenic forge
# rain wolf we are generating an enum for localization keys

I do have something similar as well (unrelated to the current SG discussion), we have 1 i18n json as single source of truth so we can pass that to localization platforms, and need to generate code to handle stuffs. Due to the lack of additional files support we did it with a regular editor script and it just reruns whenever it detects changes, it works alright but every time you change anything in i18n your commit includes like 4 other files 🙁

undone coral
#

you're trying to Microsoft Visual Studio & Windows your way into a multi-platform, not microsoft visual studio world

#

it will not work

#

this will not be the first nor last problem

#

if you want to make Microsoft Visual Studio applications, do not use Unity

#

those skills are not really translatable

#

the fewer editor scripts the better

scenic forge
#

I don't see what this has to do with VS or Windows, the game needs localization.

undone coral
#

it is hard to come from a place where you are comfortable, Microsoft Visual Studio, to a place you are not

rain wolf
undone coral
#

that is a really bonkers workflow

scenic forge
rain wolf
scenic forge
undone coral
#

i'm not sure then where you would have gotten introduced to source generators

#

maybe you are a rare C# backend developer... using Rider...

scenic forge
#

No I use VS Code, and I fail to see how localization has anything to do with what my IDE is.

undone coral
#

okay i see

misty glade
#

OK, the files are completely cursed. Let this be a lesson, don't refactor file/classes in windows/unity to just change the casing. 😐

undone coral
#

anyway i use the unity localization package, and i always do localization at the end, when it makes the most sense to

undone coral
#

if you can roll back in source control

misty glade
#

Renamed it and git kept the original casing 😐

undone coral
#

okay

misty glade
#

Nah it was months ago

undone coral
#

that's unfortunate

misty glade
#

I'm just renaming it to something else

undone coral
#

okay

misty glade
#

"IsgSceneManager" RIP

#

:p

undone coral
#

then it doesn't matter

#

how it is integrated

misty glade
undone coral
#

and you can work with unity localization throughout 99% of your product lifecycle harmlessly

#

it doesn't really make sense to iteratively translate

#

i can see how someone can think it does, but it doesn't

rain wolf
#

this is getting continued updates

undone coral
#

if you are in that kind of jeopardy

rain wolf
#

so that really is no end

undone coral
#

well you know what i mean

#

right before a release

#

not during development

#

like literally the last thing before you release something

rain wolf
#

we release weekly 😄

undone coral
#

well it's not like this can't be done in unity localization

#

safely

#

it certainly can

#

it's a very good package

#

that apes all the best stuff from everyone else

rain wolf
#

truly in awe of your experience

#

wow

#

sage

undone coral
#

okay well, i don't know, i agree it's tough

#

it's tough to know. i don't know what these games are

#

i find out bits and pieces

scenic forge
#

Is Unity localization type safe? Eg prevent referencing strings that don't exist, or knowing a string takes exactly 2 interpolation arguments.

undone coral
#

you can't use source generators in unity code really, end of story

scenic forge
undone coral
#

i think if your game is making money and you've got at hing working, you know, go for it

#

you got something

#

i don't really know

#

i've offered my perspective

#

you probably have a support contract, go ahead and use it

#

once i heard "stuffs" and "csv branch", it signaled to me a certain set of processes that require support contracts and paid advice, which i cannot give, i am sorry

proven venture
#

well they wrote a fluent api-esque system on top of ugui, so... right

#

what i meant to say was he does some pretty wild stuff

proven venture
#

burrito

undone coral
#

i see

#

i mean this stuff is really interesting

#

it is sort of subjective what the yield is on doing weird source code features

#

making things intellectually stimulating there means more game code is written, even if the intellectually stimulating stuff is low yield

#

so i do not mean to begrudge experiments in this approach at all - go ahead, use source generators and figure it out for the rest of us 🙂

scenic forge
#

SG is very powerful even not for something specific to Unity

#

(And they are also a pain to debug so its usage isn't widespread even in the wider C# community)

#

There are tons of uses for SG, practically anytime you have boilerplatey/repetitive code it may be a good SG use case.

undone coral
#

yeah i agree

#

i use source generation just not Source Generators

#

listen i mean to be supportive

#

i guess i am not familiar enough with the feature

#

i got the highest yield from embracing real build tools like Gradle

#

to solve problems

scenic forge
#

You can think of source generators as source generation but always up to date with the input (doesn't need to be run manually and invisible)

#

Source generators don't have the issue of "I have to manually run any time changes occur so they are reflected in the generated code", "I must either gitignore generated code but give instruction to how to generate that code so my project even runs", or "I must commit the generated code and keep it in sync all the time"

undone coral
#

yeah but macros are always a little radioactive

#

it makes sense to me to use them as an IDL, but then the reality is it's a network artifact, like protobufs, it's going to be out of date somewhere always

#

and in my unity streaming service, it is really high ROI to have done everything using grpc / protobufs, because it really did ensure backwards compatibility across my API

scenic forge
#

Source generators are invisible to the consumer, as long as you have it set up, you do not need to manually handle them ever and the generated code will always be in sync with input.

undone coral
#

it just sounds like they would have, in the general sense, the same problems Macros do

#

unreal engine uses a lot of macros

#

out of necessity

scenic forge
#

You mean C++ templates?

proven venture
#

ue c++ has a lot of macros for all i know

scenic forge
#

I don't know much about Unreal or C++ templates, but they are very different from C# SG

undone coral
#

they use proper macros yes

#

hmm

#

when i looked at the source generator docs just now

#

it looked like macros by another name

scenic forge
#

C++ templates directly modify and transforms your source code, SG does not.

undone coral
#

source generators can achieve "code weaving" aka bytecode instrumentation

#

which i have also seen from the java end, and takes a lot of expertise to do correctly

undone coral
#

hmm

scenic forge
#

It can only append, not modify.

#

Which makes it a lot less powerful, but a lot more sane to work with.

#

The only thing C# SG can ever do is "here's a new file I generated, include it in the project"

#

It cannot modify anything.

proven venture
#

il weaving on the other hand

#

they kind of achieve the same thing except one generates and one changes the source dll

scenic forge
#

IL weaving or any sort of modification can do a lot more than SG but yeah.

proven venture
#

but you'll need a weaving library since source generators wont do it

scenic forge
#

Yep, and it's very easy to blow things up completely and descend into madness, so it's very niche.

summer spindle
#

I REALLY need help with Local Multiplayer, anyone that have done a Local Multiplayer game that can help me or give me a link to a working Youtube Tutorial? Please!

potent sandal
#

Hey guys, hopefully this belongs in the advanced category. I'm building a small space colonizer game where you can build on planets. While I like how it's shaping up I was considering switching my current building system (place anywhere) to a tile based one to have more precise control on how buildings are placed and whatnot. The problem is the following:
All gameplay happens on actual spherical planets! I have no idea on how to begin to map a tilemap of squares onto a sphere.
Does anyone have any tips OR know any online resource on the topic? Anything is appreciated!

sly grove
#

I'm going to say right out that Unity's build in Grid/Tilemap etc are probably not going to be of use to you, and if you haven't already, you'll probably need to make your own solution.

potent sandal
gray pulsar
timber flame
#

Which one lead to more compression?
Storing the entire byte array or only filled values + indices.
I think the first one because the consecutive values can be repeated and it can be compressed more

sly grove
timber flame
#

DataStruct1[] // byte rotation, byte id --> Entire Array
DataStruct2[] // byte rotation, byte id, index --> Only Filled values

#

Yes, it depends

#

but suppose it is a world with many empty spaces close together probably

#

I use LZ4 compression as well

#

Also, I do not know LZ4 can handle repeated patterns in bytes or not
23,2,23,2,23,2
data(id,rotation),data(id,rotation),...

midnight violet
#

Why is Unity so poorly implementing Native stuff from iOS... anyone has some trick how to get the lastError for ReplayKit without constantly recieving the same error? ReplayKit.lastError will stay forever... no matter if you restart recording...

jolly token
#

Compressing algorithm does the something similar for you, so I don't think filtering will help making result smaller..

timber flame
#

Can LZ4 compress data structures efficiently if they are the same?

public struct S{
   public byte Id;
   public byte Rot;
}
jolly token
#

They should

timber flame
#

So, adding indices can ruin that compression :/

jolly token
#

Yeah it could be just adding more things to compress

regal olive
#

how do i get the width and height of 2d camera??

sly grove
#

the width is based on that height and the aspect ratio

#
float height = cam.orthographicHeight * 2;
float width = height * cam.aspect;```
regal olive
#

bruh i used orthographicSize not orthographicHeight

#

thx

sly grove
regal olive
#

how?

#

orthographicHeight dont exist

sly grove
#

you're right

#

like I said - always check the docs

#

I just typed that code above off the top of my head

onyx vault
#

I want to make a GameMode system in unity for a multiplayer game where I can override base functions to create new modes easily. Would it better design practice to have an event based system where I subscribe and unsubscribe from game events(eg player dies, player joins late) and invoke them when they occur or have a base GameModeClass and override functions that are called when the events are invoked? Also what would be the best way to manage different player prefabs for each gamemode?

regal olive
onyx vault
regal olive
#

Oh could have said that at the start 🙉 Meditative

fresh salmon
#

Would it be better design practice...
Second sentence

#

And why not? Event based is extremely versatile as it's loosely coupled, your game mode "drivers" could subscribe to the events they need from a game manager object

#

Watch out for subscription spaghetti though, try not to link events back and forth too much

regal olive
#

Hello what happens when object is destroyed using destroy
. Does it free the space it used quick

midnight violet
regal olive
#

How would i fully Remove it?

#

Like it never existed

midnight violet
#

If its collected by GC, it is removed.

austere jewel
#

To fully collect the managed side of the objects you need to also set references to them to null. Same as any C# object.

real plume
# austere jewel To fully collect the managed side of the objects you need to also set references...

want to ask about that. if i'm instantiating 50 'collectible' objects because the player did X thing, then i soon after destroy them because the player picked them up, is this the type of thing that probably would have leftover references? or do you mean explicit references by variable declaration and things along those lines? i'm just now peeking my head into garbage collection and memory so sorry if this question isn't the best phrased...

midnight violet
#

It depends on what is in the obejct. Its not just gameobject are being handled equally all over the game runtime. If you load textures for example and create texture2Ds, all of those things can affect if GC is kicking in or things never get disposed

real plume
austere jewel
#

If you Destroy something the native C++ representation is freed. As with any other C# object, references to it keep it in memory. Destroy cannot set references to null.
The references just evaluate to null via Unity's overridden equals comparison.
To have the managed C# memory ready to be garbage collected all references to those objects must be null.

#

You're likely to come along and set those references to null later by just operating on the same lists, overwriting the variables, etc. So usually you don't have to think about it

real plume
# austere jewel You're likely to come along and set those references to null later by just opera...

ok, that actually was in the vein of my next question. i'm making a game that includes a tilemap running a cellular automata process and both the memory use, heap use, and cpu use seem to rise over time so i'm trying to diagnose. the cellular automata script uses extended use of lists and dicts so i was wondering if that was part of the issue. the code isn't cleaned up for review but if you have a moment to look to see if there's any obvious memory collection or leak issues or whatever i'd appreciate it a lot.... http://pastie.org/p/3MDJEtV9NL5wFvX7Bp5ya1 - not the shortest script but a lot is repeating logic or commented out...

#

and please don't make fun of my ifs lol

austere jewel
real plume
#

thanks for the answers though i appreciate it

midnight violet
#

If several things are going on, take apart your system and profile single mechanics, loadings, instantiations, whatever is going on. And dig into it to find out

fringe sentinel
#

gonna ask here but anyone know how to fix this?

#

its all from unity default scripts
all of them being com.unity.ugui

#

while this comes from a game decompile, i first deleted the decompiled versions, then reinstalled them in package manager

#

version is 2019.2.13f1

misty glade
#

I have some frame stuttering when my client starts. In profiling it, though, I have this spike - a single frame that takes 201ms to process, but there's no single obvious low hanging fruit. Any ideas on this?

#

Is this useful? What's all this GC alloc going on?

wooden cedar
misty glade
#

both

#

I'm not an expert with the profiler, but I can't seem to identify what's actually taking up all the time in this frame

austere jewel
#

JIT is compiling a whole bunch of stuff

misty glade
#

hm... I still get stuttering on Android, which my understanding is that I'm not using any JIT at all there

wooden cedar
#

Just curious, I saw something like that once (EventSystem to taking a while) with complex UI size fitters and with best fit text. But that was mobile only.

misty glade
#

I mean, I have some fitters, but nothing here is doing any layout/UI work.. It's likely the parsing of the settings json I'm getting from the server, but ... I can't seem to prove that

austere jewel
#

There's a bunch of logging mentioned. Turning off stack traces for anything but errors is always a good first step

misty glade
#

OK, lemme see, brb.

#

Remind me where that setting is? That's a console setting? I haven't played with that setting in months

#

This stuff?

wooden cedar
misty glade
#

i'll try with deep profiling.. not sure my problem is what this guy is mentioning..

#

AHA, deep profiling uncovered it

#

and ... I'm stupid.

#

(I don't even want to share the culprit)

#

I forgot that I added some geolocation service thingy and meant to make it non-blocking but.... just forgot about it. Yes, that's a blocking HTTP request right in my game. 😐

austere jewel
#

and yes, what you had above sadly does affect both the stack traces in builds and in the editor.
I wish they were separate things. I've had to make custom build steps that set those sort of things just for builds and then reset them

misty glade
#

Yeah. I mean, it's one thing to have a clue and chase it down (and still have the hiccup), it's another to know and realize that you are, in fact, dumb today. 🙂

#

All good - I just wrote it that way because I was debugging some other thing (as a completely related aside, fuck microsoft azure container instances) and just.... forgot to do it properly with async or a coroutine

#

I've also added a little bit of pseudo-profiling and .. my MessagePack object takes 93ms to deserialize, and my initialization in unity (once it's deserialized and I set up my game world) is another 140ms, so there's still some other low hanging fruit

#
ISG: <color=#6666FFFF>Debug: LNL: Connected. Connection took 110.5901 ms</color>
ISG: <color=#6666FFFF>Debug: Deserialization took 93.0114 ms.</color>
ISG: <color=#ccccccff>Verbose: Finished initalizing. It took 144.6879 ms.</color>
#

(all of those steps are sync atm)

#

Anyway, I'm rambling. Thanks for the help.

blissful bay
#

Hi, Im looking for a high-performance way to find a closest point to another point, right now Im using this https://gdl.space/feqegiyidu.cpp
but Im worried that this wont perform well enough without sacrificing accuracy
there has to be a better way to do this, right?

midnight violet
blissful bay
#

it takes floats from 0 to 1

midnight violet
#

Alright, and the ontriggerstay is on one object or on multiple? what is ClosestPoitnFound doing

blissful bay
#

the idea is that the player is supposed to "drag" an object along the curve, this script is on the object they are supposed to drag, when their finger is in its collider, the ontrigger stay is looking for the closest point from the finger on the curve, ClosestPointFound then moves this gameObject to the point that has been found

sly grove
#

save the result in a variable and reuse it.

#

Same with other.transform.position

#

Actually this whole thing:

dist.x = pathCreator.path.GetPointAtDistance(f).x - other.transform.position.x;
                dist.y = pathCreator.path.GetPointAtDistance(f).y - other.transform.position.y;
                dist.z = pathCreator.path.GetPointAtDistance(f).z - other.transform.position.z;```
Could just be ```cs
Vector3 dist = pathCreator.path.GetPointAtDistance(f) - other.transform.position;```No?
blissful bay
#

I have read that calculating the x,y and z separately was faster than using the vectors as a whole

#

but I havent tested it yet

sly grove
blissful bay
#

needless to say, calling the method 3 times is a mistake nonetheless

blissful bay
#

is there a way to do the entire logic better tho? I dont really have a good feeling about the way it is now

#

but I wasnt able to come up with anything better myself yet

sly grove
blissful bay
#

not that I am aware of

#

I will go through it once again, gimme a while

sly grove
#

looks like it might do some kind of binary search under the hood too

#

which is promising for performance

blissful bay
#

it actually does, I just missed it the first time

#

I dont really understand how it works, but it probably does

blissful bay
analog nexus
#

How come HttpMethod.Patch exists and works for some people but not others

#

it just throws on access

#

and yet - it works for me

#

and my colleague

alpine adder
#

what is the best practice for creating a currency system in my game? I see a lot about playerprefs but I was thinking more saving to a file? especially as a long term goal would to get this on aws for multiplayer

regal olive
alpine adder
#

I see so this will work and eventually I just move this over to aws?

stuck onyx
#

anybody debugging on device on a mac? can't attach visual studio to the unity process of the phone

regal olive
alpine adder
#

no sure never done multiplayer saving before tbh

#

I have no idea how that works lol

#

but the thought of an api call everytime gold updates does seem extreme

regal olive
#

For serve side saving use PHP and MySQL

alpine adder
#

how does saving work though? is it really a server call for every input?

flint sage
#

It depends on how you approach things

regal olive
#

You could save data on when they exist game

flint sage
#

If you want the minimum amount of cheating possible then you need to validate everything on the server

stuck onyx
#

save*

flint sage
#

E.g. user buys something? Server validates and executes everything and only tells the client to update the inventory with x items and x gold change

regal olive
#

Yeah or he could save it on som secure file first and move it to the server

stuck onyx
#

I dont know about your project, but for the moment i recommend you to ignore possible cheating

#

if people cheats on your game means you have become succesful

#

if you have become succesful a few cheaters will be the least of your problems, believe me

#

dont waste your time on that

#

i tell you by experience

regal olive
#

Yeah they come when the game gets population

stuck onyx
#

yep

#

think about more important things like scalability

#

game mechanics

#

marketing

regal olive
#

Also fighting cheaters is pain in the ass

stuck onyx
#

leave the anticheating for when you become succesful, if youdo

#

there will be ALWAYS cheaters, thats unavoidable

alpine adder
#

so im making just a simple multiplayer td

#

although nothing multiplayer is simple lol

#

so think just get gold build towers

stuck onyx
#

but wasting your time creating a super safe anti cheating game its stupid.

#

i mean wasting it now

alpine adder
#

just trying to think through the currency system for the time being

#

and how that can be done

stuck onyx
#

what are you using as database?

regal olive
flint sage
#

You should probbaly just do peer 2 peer networking instead of some centralized system for some simple TD game

alpine adder
#

I have nothing set up 😄

#

I just have normcore atm

#

and got people to join database and the rest is still all in the works

#

learnign about this thank you all!

#

going to hook it up to a firebase db?

#

does that sound correct?

#

a SO wouldn't work right

gloomy mica
#

Playable API question. How to set an existing AnimationClipPlayable's clip to null (without recreate the playable)?

#

there's only a GetAnimationClip() function, but when I inspect the Animator's Graph via PlayableGraphVisualizer, the playable can set clip to null without recreate itself

undone coral
#

on phones?

alpine adder
#

I see thank you! I did some research and came to azure playfab. Im curious to try it out

#

im sure the learning curve will be fast hahaha

undone coral
#

is this for a phone?

misty glade
#

I have some weird and difficult to diagnose problems with UGS in app advertising.. Randomly and without any discernable error messages or logging, the sound devices don't resume when coming back from an interstitial. The sound plays before, the sound plays from the interstitial ad, but coming back to the client .. no sound. Any ideas? Edit: On Android devices

undone coral
#

is this for an http server you control, or something else?

#

in unity, you use unitywebrequest, not system.net.httpclient

undone coral
#

if your deserialization involves huge, huge huge strings

misty glade
#

this is strictly my messagepack deserialization.. not sure ..

undone coral
#

maybe

misty glade
#

they are :p

#

19kb json

undone coral
#

that's fine

#

but i mean

#

inside the json

#

is it 18.999kB of strings

#

isn't msgpack a binary format..

misty glade
#

nah it's mostly small strings and primitives

#

yeah

undone coral
#

hmm

misty glade
#

it's 19kb packed

undone coral
#

it doesn't really take 93ms to deserialize 19kB of data

#

it might take 0.2ms, or 1ms in the worst case

#

or less

misty glade
#
                    d("Received configuration info from game. Unpacking settings and initializing systems.");
                    _startedConfiguration = DateTime.Now;
                    ServerSendConfiguration ssc = UnityNetworkingUtils.Deserialize<ServerSendConfiguration>(msg.Message);
                    TimeSpan ts = DateTime.Now - _startedConfiguration;
                    d($"Deserialization took {ts.TotalMilliseconds} ms.");



        public static T Deserialize<T>(byte[] value)
        {
            return MessagePackSerializer.Deserialize<T>(value);
        }

undone coral
#

can you ask msgpack for a dictionary instead of your object?

misty glade
#

that's the 93ms call

undone coral
#

hmm

#

i would maybe use stopwatch

#

or Profiler

#

profiler is the most reliable

misty glade
#

it's pretty much only MessagePackSerializer.Deserialize

undone coral
#

i wouldn't use datetime.now

#

a call to datetime.now can take a long time lol

#

on a device

#

believe it or not

misty glade
#

Yeah, I mean, that's fair, I was just looking for magnitude of order issues

undone coral
#

because it needs to load timezone data

misty glade
#

really? lol, didn't know

undone coral
#

yeah

misty glade
#

I use UtcNow almost everywhere, fwiw - does that avoid that timezone overhead?

undone coral
#

in webgl, at some point, calling datetime.now in a mobile browser took 2.7s

#

you shouldn't use datetime ever

#

if you can avoid it

misty glade
#

or does that still need to .. "unconvert" my perfect time (pacific time best time) to utc

#

that's crazy, TIL

#

I use it extensively on my server.. 😐

undone coral
#

that's fine

#

i mean in unity

misty glade
#

ah

undone coral
#

i don't totally comprehend why unity's implementation of datetime is so bad

#

it is the Built In Render Pipeline of time functionality

misty glade
#

so, the object that msgpack is de/serializing here is .... quite large, i don't think 93mb ms is out of bounds

undone coral
#

you're going to use Profiler.BeginSample

#

it's going to be like 0.2ms

misty glade
#

ok lemme try, standby a sec

#

wait profiler is a unity thing? should i use stopwatch or profiler? i just want to see the ms delay in console output, not have to fire up the profiler to dig into it

undone coral
#

because it will give you valuable context

misty glade
#

Profiler.BeginSample is conditionally compiled away using ConditionalAttribute. Thus it will have zero overhead, when it is deployed in non-Development Build.

Oh, actually, yeah, this is nice

undone coral
#

yes

#

it will be absolutely correct in editor for small stuff

#

it will be relatively correct for big picture performance

#

so you can use it to optimize in editor, but if you need absolute performance, you should measure big stuff like total render time in standalone builds

analog nexus
misty glade
#

Is there any way to get a profiler frame data out to the console? or do I have to enable the profiler to view this info

undone coral
misty glade
#

I'm mostly just interested in this chunk of init code

undone coral
#

you will be able to find it easily

misty glade
flint sage
misty glade
#

like, i did that just to get roughly what's failing

misty glade
undone coral
#

unfortunately that will give you wrong answers because of the imprecision of DateTime

misty glade
#

"ssc" in the snippet above is rather large

flint sage
#

Chances are then that msgpack is generating more optimized systems to deserialize in the first call

undone coral
#

i don't think msgpack in unity emits

#

and reflection is slow but it's not that slow

#

i don't know if it caches the results of attributes. i don't use attribute annotation based stuff

misty glade
undone coral
#

you can also try marking classes as sealed if it is properly caching the reflection results

misty glade
#

all of the object classes are sealed and .. pretty plain, but I don't think that makes a difference, since messagepack is generating its own code for deserializing.. but i can't read that particular code since it's a source-generated-mess

#

7700 lines

undone coral
#

if it's generated sources* (not a .net source generator)

misty glade
#

yeah, required for android

undone coral
#

i guarantee you it does not take 92ms

#

it's going to take closer to 0.1ms or less

misty glade
#

hm.. ok, doing the profiler thing

undone coral
#

it's going to be immeasurable

misty glade
#

standby 🙂

undone coral
#

it will probably create a lot of GARBAGE which almost all deserialization does

#

but that will not show up in the time it takes to deserialize

undone coral
#

it really depends on your objectives

misty glade
#

that's fine, I don't mind garbage since.. theoretically that can be cleaned up later (and is hopefully optimized a bit not to lock up rendering threads)

#

what do I do with this profiler frame? do I just look for it in the profiler? it'll have it's own line item?

#

(sorry, trying to read and digest the API for Profiler. really quickly)

#

that's it?

undone coral
#

then scrub the timeline

#

around when it is called

misty glade
#

oh i can get it in the profiler no problem since it happens on demand (when I click "login" in the client and run the server locally)

undone coral
#

okay great

misty glade
#

it'll be a spike i'm pretty sure

#

standby

#

hm... where do i find it..? i think i have the frame but I don't see the profile sample I made

undone coral
#

you should see the list of methods at the bottom

#

that are being called

#

one view is the hierarchy, another is the timeline

#

you can also see it shows you only Main Thread

#

you can change which thread if it's not being called on the main thread at all

#

but the best way to od it is to type SSC into the search box

misty glade
#

k

undone coral
#

then scrub gently around when you clicked login

#

and look carefully at the hierarchy view, it should appear

misty glade
#

crap "SSC" is found in "IsScene"

undone coral
#

lol

#

you can also write MessagePack

misty glade
#

"Deserializer" is probably the unique search

undone coral
#

sure

misty glade
#

messagepack was my next guess but obv that failed

#

hundreds of mp calls :p

undone coral
#

and gently scrub

#

hmm, just to confirm you do not have Deep Profiling turned on correct?

#

it should be turned off

misty glade
#

oh, i have it on

undone coral
#

turn it off and run it again

misty glade
#

i couldn't find the call anywhere

analog nexus
misty glade
#

k - i'm going to name the key "pangloss" because you deserve the credit 😉

undone coral
#

is it not being called on the main thread? turning off deep profiling will reduce the noise significantly

undone coral
misty glade
#

it's being called on the main thread, yes (it's on my TODO to offload this but.. for now it's on the main thread)

undone coral
#

and unitywebrequest, on most platforms, is using libcurl or the platform http client

#

you shouldn't ever use httpclient

#

it's a major sticking point for people

analog nexus
#

Says who

undone coral
#

listen i'm not a content creator and i don't aspire to be one

#

relying on content creators for programming knowledge is a guaranteed way to ship a game very very late

misty glade
#

You owe me a beer

undone coral
#

so the sooner you start using unitywebrequest the better your game will perform and the fewer bugs you'll experience, on all devices

analog nexus
#

Again, it is understandable that mono is not implementing everything, this is also not my question. The question is why it is working for some people, possibly hinting at a bigger problem of framework version mismatch between people

undone coral
#

i think at this stage you can now enable deep profiling and see what exactly is taking so long

analog nexus
#

I don't know what you're on about about content creators

misty glade
#

Yeah, I mean.. I could but.. I'm a bit frazzled with launch timeline - I think I'm just going to offload the MP deserialization to another thread or coroutine it or something

#

it works just fine and literally it's one little burp during startup.. I feel like people are mostly ok with a little jankiness during load screens

undone coral
#

because the big difference between self and time is looking not great

misty glade
#

the music plays smoothly during the loading anyway, it's just a little bit of framerate stuttering

undone coral
#

yeah it's going to be fine

#

it is easy to offload

undone coral
#

unity certainly says use unitywebrequest

#

anyway

#

this isn't going anywhere

analog nexus
#

Well you appealed to authority without backing up your claim

undone coral
#

i told you the facts of the situation

#

that httpclient isn't fully implemented

misty glade
undone coral
#

there isn't more of a story than that

analog nexus
#

I didn't ask for facts about UWR vs .net

undone coral
#

lol

#

the stars

#

you can easily offload it... with unitask 🙂

analog nexus
#

I asked about how some people have different .net implementations

undone coral
#

unity standalone player doesn't fully implement httpclient

#

so you cannot rely on it 100%

analog nexus
#

But they do. It works for me and doesn't for others

undone coral
#

it's okay

#

you are welcome to bust your head against this bug

#

you can ship your game late

#

it's your game

analog nexus
#

Are you saying it stops working once you go from editor to a build

undone coral
#

if you want to die on the hill of "muh visual studio" go fo rit

undone coral
analog nexus
#

I'm not even using VS

undone coral
#

there are methods that are empty

#

or buggy or incomplete.

#

it's that simple

misty glade
#

Dr.P when we start our next game I'm going to have a big long chat with you about UniRX because .. I'm too far in to refactor it (remember when we talked about it like a year ago and I said "this looks cool but I'm going to stay the course" - I wish I hadn't!). Next project is going to be rx based for sure.

misty glade
#

I occasionally see you promoting it in answers and I always have a little giggle and sad head shake that I didn't listen earlier 😛

undone coral
misty glade
#

We're doing animation bugs and stuff and ... gosh, what a headache. It would have been so nice to just drop animation events into a stream

undone coral
#

i am trying to emphasize i don't know why you feel so strongly about using an API that is not supported in Unity versus one that is

#

it would take you an hour to rewrite everything to use the working API. depending on what the game is it might even be 5 minutes

analog nexus
#

Well the one that is supported by unity is not implemented in the same why as mono

misty glade
#

I can't recall if I told you my non-rx solution.. I literally copy a data structure on the server and client, then copy it again on the client, one for the "true" data and another for the "animated" data, and then merge them all up at the end. It works, but man, so fiddly..

undone coral
undone coral
#

that's reinventing UniRx

misty glade
#

cursed comment

undone coral
#

like at an intellectual level

misty glade
#

I mean, it's only now that I realize that this fundamentally IS rx

misty glade
#

and so all the work I did... doing this... was just wasted effort because my implementation is not as good as UniRX (probably is)