#archived-code-advanced

1 messages ยท Page 14 of 1

undone coral
#

downloading 2x more GBs is worse than developing something that doesn't work

#

having just done this successfully i don' tknow, you ought to listen to me

#

i wouldn't start developing Tests with a capital T for something you are actively developing right now anyway

#

in reality, you have to work on yours and the collaborator's projects simultaneously

#

it's unavoidable

#

if you are perhaps working with someone external with their own repository, you know, that is hard

#

that was an error

#

hopefully you get to see the external source

#

i had my projects "polluted" this way

#

it was fine

#

but i never tried to ship in a scene

#

i'm not sure why i would do that

#

like i could ship in a demo scene, but i could also make a prefab

#

and if the user wanted the demo or test content or whatever

#

well you can drag and drop the prefab into a new scene

#

or do that programmatically

#

how are you building the "host projects"?

#

you mean on your local device?

#

are we talking about 3-5m builds? or github actions with game-ci

#

or something else

tropic locust
#

๐Ÿ˜Š i actually think I misunderstood the TestRunner. It actually creates a scene to run the tests. So I think I won't need the test scenes at all. And the scenes were actually not my main concern. That is solved. I am just wondering now if the addressable items I use for testing will get bundled with each host build. But if I put them in Samples I think that solves the problem

undone coral
#

it creates an empty scene, but it really depends on what you're testing if you need a scene. re: addressable items...

#

you should look at the addressables repo and see what they do for testing

tropic locust
undone coral
#

or if you aspire to do that

#

like you have your own host project, which i understand is your playground for working on the package

#

is that built via automation? do you want the automation to run those tests?

tropic locust
undone coral
#

that might be helpful

#

the link i sent

#

is your goal to eventually have a publicly distributed package with some kind of proprietary / private / licensed code that gets built into unity (as opposed to a backend)?

tropic locust
#

Not yet cause we are only actively developing the package. The host project is discardable

#

Thanks a lot guys!

#

Awesome @regal olive thanks a lot. I will probably reach out ๐Ÿ˜Š

left mauve
#

Hi guys i have a question... how do i (in code) set the tiling/offset values for detail-maps?
It seems there is no keyword or i am missing something.

left mauve
#

This is for the main material. I need something similar for the detail maps.

#

I need the ... well the name for the detail thing

jolly token
#

Right on the doc

left mauve
#

So i can use: m.SetTextureOffset("_DetailAlbedoMap", xyz)?

#

Okay.. interesting. I will try that. I never used that before

#

m.SetVector("_Tiling", xyz) is what i have currently in the code - it never came to my mind to use any other method. But it has a clearer name and it makes sense i guess. So i will switch

#

Thank you!

jolly token
#

No problem ๐Ÿ™‚

azure hinge
#

has anyone created a CinemachineExtension and updated the position in PostPipelineStageCallback ?

#

I'm having issues with the one that I created but can't figure out why

undone coral
#

i modified an existing one

silent jungle
#

is it possible to send in an array of compute buffers into a compute shader?

#

I have a user defined variable that determines how many compute buffers will be used and I cant seem to find a way to send them into the compute shader without manually writing a shader that compensates for the specified amount

undone coral
#

shouldn't it be

buffers.Select((buffer, index) => 
 return new Buffer(buffer) {
  bufferIndex = index
 };
)
```?
#

do you see what i am saying @silent jungle

rugged radish
#

hey guys, when you dispatch a compute shader, does it prevent GPU / Unity from rendering new frames until the shader is done running ?

rugged radish
#

on the running time of the shader I assume ?

undone coral
#

no

rugged radish
#

interesting, must be compute buffer visualization routines then

undone coral
#

so when you say "dispatch a compute shader"

#

what do you actually do? use its output for rendering?

#

use it on the CPU first, and then for rendering?

rugged radish
#

no, I read it back, it's data that is used by CPU later and don't use for rendering

undone coral
#

okay

rugged radish
#

readback is async

undone coral
#

so compute and graphics commands on modern AMD and NVIDIA GPUs run in genuine parallel

#

you can see this by enabling gpu profiling of a standalone player build. to profile a compute shader, you should use Nsight or PIX. if you are using the latest 2022.2 alpha, directx12 is finally released and use -force-dx12 -force-gfx-jobs native

rugged radish
#

is it a DX12 exclusive feature (the parallel graphics + compute execution) ?

undone coral
#

i think it works with dx11

#

but i'm not 100% sure

rugged radish
#

time to profile the async code that runs that and see what actually causes the long hangs
hate profiling async code ๐Ÿฅฒ

undone coral
#

it doesn't prevent the GPU from rendering new frames

#

in any case

#

if you are not using the output for rendering

#

it slows it down.

#

how much it slows it down really depends on your hardware

undone coral
#

or tools inside unity

#

you should probably use the 2022.2 alpha

rugged radish
#

not used for rendering
there are some visualization routines to inspect the results, hope it's them that freeze up rendering

undone coral
#

or use Metal

rugged radish
#

they supposed to be very simple, but maybe

#

I'll update to 2022.2 as soon as it releases, this is not urgent

#

on 2022.1 rn

undone coral
#

you have to test SystemInfo.supportsAsyncCompute

#

and yes it's definitely only directx12

rugged radish
#

oh cool, I'll test it rn, thanks โค๏ธ

undone coral
#

it will return false

#

it might return true on 2022.2 latest alpha

rugged radish
#

oh, that's unfortunate

undone coral
#

false on nvidia*

#

might return true on AMD

vocal dagger
#

Currently profiling, im seing many GC.Alloc calls within the .Get method which i can not explain.
I assume the .Get method calls () => asset.InstantiateAsync().WaitForCompletion() callback... is it possible that the lambda produces some sort of closure allocation ? Any help would be great...

    public class AdressableAssetsPool : UnityEngine.Pool.ObjectPool<GameObject>{

        public AssetReference asset;

        public AdressableAssetsPool(
            AssetReference asset,
            Action<GameObject> actionOnGet = null,
            Action<GameObject> actionOnRelease = null,
            bool collectionCheck = true,
            int defaultCapacity = 100,
            int maxSize = 250
        ) : base(() => asset.InstantiateAsync().WaitForCompletion(), actionOnGet, actionOnRelease, o => Addressables.ReleaseInstance(o), collectionCheck, defaultCapacity, maxSize) {
            this.asset = asset;
        }
    }
rugged radish
#

yep, no support

undone coral
#

what is going on here though

vocal dagger
undone coral
#

why are you pooling this?

#

yes

vocal dagger
#

Im pooling the gameobjects created via the assetreference xD

#

Its a wrapper class basically for some custom logic

undone coral
#

you should only have the asset reference instantiated once, since it's a prefab, right?

#

then you would pool that game object

#

instead of instantiating from the asset reference every time

#

also why is it wait for completion?

#

pooling isn't async

#

i mean there are async pools if that's what you need but it wouldn't make sense to od that

vocal dagger
undone coral
#

i don't know

#

i mean i don't really touch this stuff

#

i mean clearly you can profile it and it'll tell you

#

you can add the sampler lines to your callback

#

and see if instantiateasync does "gc.alloc"

#

however, if it's a small alloc i would chalk it up to the "do not care" column

vocal dagger
# undone coral i don't know

That alloc gets called like 2500 times which generates like 500kb garbages so its actually quite big and causes a noticeable frame drop :/

#

I also can not make that callback a method reference since it tells me it needs to be static

jolly token
#

Are you sure they are actual garbage not the necessary heap alloc for game objects?

vocal dagger
#

I have no damn idea, even deep profiling just tells me that theres "GC.Alloc" happening... but it does not tell me what exactly causes it... but i assume that its that piece of code

#

Thats what happens inside the pools.Get method

#

It instantiates like 15 gameobjects which makes sense

#

and than like 2500 gc.allocs

#

which doesnt make sense anymore

#

all by calling "myPool.Get()"

jolly token
vocal dagger
#

I did... the picture above is the result

jolly token
#

Oh okay. So total memory alloc is 236kb?

#

I think GC alloc is just getting called internally from Instantiate?

vocal dagger
#

I cropped the picture a bit wrong, but its actually about 500kb... almost 250 from the instantiate calls and other 250 misterious kb garbage from "GC.ALLOC" which could be literally anything

vocal dagger
#

As you can see i already expanded the instantiate call and the gc alloc is next to it, so not sure if its really tied to that one

jolly token
#

Ah the screenshot has confused me lol

vocal dagger
#

Oh sorry, heres a clearer one

#

I named the profiling sample "INIT" and well... the instantiate is next to the gc.alloc so i guess those are two different ones

#

This is how it actually looks like

jolly token
#

Can you provide the code you used to profile those?

#

So we can see what method calls are in the sampler scope

vocal dagger
#

Of course, but you might laugh...

#
                Profiler.BeginSample("INIT");
                var go = pool.Get();
                Profiler.EndSample();
#

Tada

#

Its literally just the pool.Get method

jolly token
#

and it's deep profiling? ๐Ÿค”

vocal dagger
#

Yes and it makes me wanna cry

#

But as stated above i extended the pool like this :

#
    public class AdressableAssetsPool : UnityEngine.Pool.ObjectPool<GameObject>{

        public AssetReference asset;

        public AdressableAssetsPool(
            AssetReference asset,
            Action<GameObject> actionOnGet = null,
            Action<GameObject> actionOnRelease = null,
            bool collectionCheck = true,
            int defaultCapacity = 100,
            int maxSize = 250
        ) : base(() => asset.InstantiateAsync().WaitForCompletion(), actionOnGet, actionOnRelease, o => Addressables.ReleaseInstance(o), collectionCheck, defaultCapacity, maxSize) {
            this.asset = asset;
        }
    }
#

And i think its a closure memory allocation ( the first lambda in the base )

jolly token
#

closure should allocate once

vocal dagger
#

Since that method is being called when calling .Get

#

Hmmm well

jolly token
#

Unless you are making closure from loop

vocal dagger
#

The pool.get method gets called inside a loop, does this count ? xD

jolly token
#

But the pool constructor is outside loop :0

vocal dagger
#

Hmmm right

jolly token
#

Do you pass anything to actionOnGet?

#

Or other way: You can use GameObject from LoadAssetAsync instead

#

as a prefab

chilly nymph
vocal dagger
#

Not really, its just a empty lambda...

jolly token
#

I meant using LoadAssetAsync to load prefab and do regular Instantiate

#

If you don't need reference count of addressable, that's valid approach

#

Maybe Addressable is allocating something for async operation

vocal dagger
jolly token
#

Hmmmm.

vocal dagger
#

Btw is that really the right way to instantiate adressables ? I can literally only find examples with InstantiateAsync... the website actually says :

#

So it sounds like you should actually avoid that

rugged radish
#

it just says that you can shoot yourself in the foot

#

if you aren't careful

jolly token
#

I mean even if there is closure allocation it's only gonna take about few pointer size per call

#

Anyways it's okay to do that if you keep your original prefab's handle, not releasing it

rugged radish
#

I use the loadasync + Instantiate approach with pooling, no issues

vocal dagger
#

Uh that load/instantiate approach really did decrease the GC.ALLOC count

#

Now its just 1.4kb and not 240kb

jolly token
#

Oh so it is addressable doing it ๐Ÿ˜Œ

rugged radish
#

there's a mention that addressables system has internal tracking mechanisms, that can be disabled

jolly token
#

That's rather drastic reduce tho

vocal dagger
#

Looks like, i really assume it was the Async instantiate which than allocates a AsyncHandle which is a class if im correct ๐Ÿ˜ฎ damn

rugged radish
#

or just use the load + instantiate, which is pretty much the same

vocal dagger
#

Okay thanks a lot ^^
Just a small other issue... if i do that LoadAssetAsync and Instantiate approach, what should i do if i destroy an pooled gameobject ?

Should i call Adressables.Release/ReleaseInstance ? Or just Destroy(go) ?

jolly token
#

Since you create them with regular Instantiate, you should use regular Destroy

vocal dagger
#

Alright that makes sense... thanks ๐Ÿ˜„

rugged radish
#

you release only when you no longer need that prefab (zero objects of that type left in the scene)

vocal dagger
#

So it actually does not count the refereces and i need to manage that by myself, right ?

jolly token
#

Yes, it will only count for prefab that acquired with LoadAsync

vocal dagger
#

Great, thanks ! ๐Ÿ™‚
So just LoadAssetAsync, Instantiate, Destroy and once there no more instances left, Release

pale pier
#

Is there a way to completely disable a rigidbody without removing it?
I have this rigidbody I need to parent to my character controller and need it to act as part of the parent rigidbody collision wise, marking kinematic doesn't work

silent jungle
# undone coral why isn't the compute buffer itself an array of structs?

thanks for responding, it looks like I misunderstood exactly how to use DrawMeshInstancedIndirect. I originally thought that you created a compute buffer with information you wanted to use per instance and this buffer would be the bufferwithargs parameter for the draw function. This lead me to believe that the size of the compute buffer directly controlled how many instances would be drawn

After alot of investigating I found that there are actually 2 (or more) compute buffers to be used with the DrawMeshInstancedIndirect; the Args buffer and the custom data itself. What I cannot find however is what each parameter in the args buffer does.

The Unity documentation states that compute buffers under the indirectarguements type requires atleast 12 bytes, but cannot seem to find solid data on what those 12 bytes are supposed to represent (the example in the DrawMeshInstancedIndirect documentation has the args buffer be a 4 int array that represents index count, instances count, index start, base vertex but that doesnt seem consistent with other examples)

I designed a solution around my flawed understanding but I realize I need more resources to fully know how to utilize DrawMeshInstancedIndirect, do you know where I can find this? I already googled and most I see are showcases of how amazing the results are :p

silent jungle
pale pier
#

No way you can just do that!!!!!

#

Yep, the Rigidbody class doesn't have an enabled field

silent jungle
#

ah your right
maybe try this then :

rigidbody.isKinematic = false;
rigidbody.detectCollisions = false;
pale pier
#

Unfortunately that doesn't work as well.
Thanks for trying nonetheless.

#

Strange that Unity doesn't provide this sort of behavior, almost all components can be turned off.

jolly token
undone coral
sly grove
sage temple
#

not sure if this is considered beginner or advanced but what's the best practice for disconnecting the camera (or unparenting) when the player goes offscreen

brisk pasture
#

can just call SetParent on its transform

#

camTransform.SetParent(null, true)

#

or you could just never have the camera parented to the player in the first place

#

but have a script on the Camera that has a LateUpdate method and follows the player using it when needed

sage temple
#

Its just a demo game for a school project but we still want to do our best and its good to know

brisk pasture
#

SetParent is easier and works if the camera follows the player perfectly

#

having not making it a child of the player and just following the player is better if you want to do easing or if the camera does not perfectly follow the player

silent jungle
pale pier
jolly token
pale pier
#

It'd break references tho, anything referencing that rigidbody will no longer do.
Wish there was an easier way but doesn't seem like it.

jolly token
pale pier
#

That's unsustainable, you'd have change a majority of your codebase to be able to do this.
And you might even come across some third party tools that you want to use but can't/don't want to modify to fit that workflow.
Seems much more straight forward to just setup a placeholder collider that fits the object.

shy spruce
#

When loading scenes additively, is there anything special I need to do to get events like OnMouseEnter to fire for objects with colliders in the subscene? When an object is in the main scene, my events fire. But when I move it to the additively loaded scene, they do not fire

undone coral
shy spruce
fallen hare
#

Hey, so does anyone know how to cast a method?

i have this:


 [SerializeField]
 private string move = "Move";


//method to store
 Vector2 getVal() {
     return playerControls.Default.Movement.ReadValue<Vector2>();
 }

public class EventTrigger<T> {
    public delegate T TriggerFun();
}

//store method for later use
public void addEventTrigger<T>(string name, EventTrigger<object>.TriggerFun triggerFun) {
        if (!data.Events.ContainsKey(name)) {
            data.Events[name] = new Dictionary<Type, EventTrigger<object>>();
        }
        data.Events[name][typeof(T)] = new EventTrigger<object>((EventTrigger<object>.TriggerFun) triggerFun);
        moveList.Add(name);
}
 
/*requires a method with an "object" return type,
but recieves a method with a "Vector2" return type*/
addEventTrigger(move, getVal);

I basically want to store a method with any return type and cast it back and call it later

Thanks in advance!

jolly token
#

The ones you are trying to cast is just completely different types

muted root
#

What is the easiest way to detect if an object (the door) is between another object (my cursor, the sphere) and the camera, and hide this door automatically.

#

Basically, I need to auto hide some objects when they are between my cursor and the camera.

glass vessel
#

My first thought is some raycast or spherecast type stuff

#

but that might not be ideal if you have a big sphere like this where perspective is gonna matter

muted root
#

Well the sphere cursor will actually be very small once I've updated my code, it's just an indicator to show where the camera is looking at so in the end, it should be 10 or 20 times smaller or something like that.

#

But for the raycast, how would that work ? Basically, it would be checking of either of the four corner of my camera rays and the center of my cursor are colliding with a gameobject?

glass vessel
#

Thereโ€™s a bunch of ways to go depending on how you wanna balance simplicity, performance and accuracy.

A simple way would be to do a spherecast the size of the cursor from the center of the camera into the cursor. Anything it hits should be faded out.

This method would probably miss hitting some things close to the camera, but based on your example I donโ€™t expect that would be a huge problem.

#

Note: I should specify that Iโ€™d do a SphereCastAll, and use something like Layers or Tags to identify objects that should be turned off if hit

fallen hare
uneven star
hearty adder
#

Has anyone worked on Vulkan gfx plugin for Unity?

Can you explain a bit about the difference between IUnityGraphicsVulkanV2 and IUnityGraphicsVulkan from the IUnityInterfaces? My understanding is that V2 is supposed to be more recent compared to legacy Vulkan, which may have better device support. But couldn't get anything concrete on that from Unity Docs or Vulkan spec.

Thanks

fallen hare
livid kraken
muted root
#

I didn't know about sphere casting but this is indeed an easy method to implement. I'll give it a shot. Thanks for the help ๐Ÿ˜‰

hot dock
#

I have a small but annoying problem. I have this class which is a simple serializable tuple. Nothing really complicated...

#

But for some reason... I am getting weird console errors

#

I am a total loss as for what could the problem be, since there is really not much output to the error...

#

These are Editor errors, not compilation errors

fathom yew
hot dock
#

CaptainType is an ScriptableObject

#

It should be serializable by default, no?

jolly token
hot dock
#

Are you asking me where I am using it?

jolly token
#

Yes

hot dock
#

Well, I wouldnt have to use them, if Dictionaries would Serialize better

#

It is basically a hack, to make a List<T> like a Dictionary

jolly token
#

No I meant where is the variable that using the type ๐Ÿ˜Œ

hot dock
#

mmm.... i dont get the question

#

I am using it like this

jolly token
#

Ah okay and TamaAbility is another SO I guess?

hot dock
#

No, that is a MonoBehaviour

jolly token
#

Oh. I see. and any Editor extension are you using?

hot dock
#

I dont think so, no

jolly token
#

No custom editor? hmm I think it should work

hot dock
#

Yeah, i think so to... ๐Ÿ˜›

#

But it does not

jolly token
#

May not related but what is the warning under Tactics namespace?

hot dock
#

thats nothing

#

the "namespaces" not being named like the folders

#

๐Ÿ˜›

buoyant spear
#

So I am trying to make a tool ingame to see things like GPU, CPU, and RAM usage % in game. Would using the Unity ProfilerRecorder be the best way to go about it?

undone coral
undone coral
# muted root What is the easiest way to detect if an object (the door) is between another obj...

observe you have made a decision about how to turn the 2d area (a circle of interest in the middle of the camera) into 3d space. if you move the camera back for example, you'd want the sphere of interest to still be in the middle of the room, so it's not as simple as "a fixed distance."

cinemachine uses a spherecast to determine visibility, you can look at its source. if you're already using cinemachine, author a subclass of its preexisting visibility extension to hide and show objects instead of moving the camera

with cinemachine you'll use the target instead of a fixed distance, which will solve the main problem you have - how do i turn 2d into 3d spaces?

undone coral
#

i'm not sure because i don't use uielements

#

but it looks like you are trying to make a custom event

#

or something that should be in a ChangeEvent

#

why are you using the UIElements event dispatcher for game logic?

hot dock
#

That had nothing to do with UIElements...

undone coral
#

@hot dock it says in the error, UnityEngine.UIElements.EventDispatcherGate

hot dock
#

Yeah, I know. But I do not know why.

undone coral
#

okay

#

what version of unity are you using?

buoyant spear
hot dock
#

2022.1

undone coral
#

there is nothing wrong with the code in CaptainPrefabTuple

hot dock
#

Yeah, that is what I thought...

#

Could it be a quirk of Unity for Linux?

undone coral
#

well

#

are you asking, does the unity editor have bugs on linux? yeah

#

uielements is coming up because an editor view is trying to render an inspector or something for the class

#

is there anything else going wrong?

#

like can you not see this type as an inspector field / in an array?

undone coral
hot dock
#

No, that is the only error/warning I get

#

If the message was not there, I would think that everything works as intended

undone coral
#

don't know why you want to do this though, because the type doesn't matter at all

#

you should have a EventArgs class, and it can have an int value field

#

or fields for the types that you will eventually use, which are extremely few

#

you know all the types ahead of time, so you can greatly simplify what you are doing

#

it'll be like, an int, a float, and maybe two ints

glad badger
#

If I want to exclude certain dlls from build for certain targets, like exclude MyGame.Server dll from client builds and MyGame.Client dll from server builds, would I just use the includePlatforms and excludePlatforms in the asmdef for that? (sorry been away from Unity for a while and rusty as hell)

#

also, love that they added the dedicated server target ๐Ÿ™‚

undone coral
#

you can use asmdefs everywhere with autoreferenced checked off, so that 100% of the code in your assets directory is covered by them

#

then, for example in your scripts folder, check the asmdef's box for autoreferenced

#

however, i would say... don't worry about it

#

you cannot practically toggle code like this. you can certainly use a compiler define

glad badger
#

ah I gotcha. So I would have to manually do that for each build target

undone coral
#

but it's a huge hassle

#

no the build targets are not related

#

the build targets and platforms have nothing to do with what you are asking for

#

there's no such thing as a server or a client build. i know it looks like there is in unity, but there isn't. there also isn't a file in your Assets/ folder called MyGame.Server.dll

#

there's an asmdef, and you're talking about DLLs that appear in the folder directory you get when you build a standalone player

glad badger
#

I mean the resulting dlls from those asmdefs

undone coral
#

it really depends on what your goals are. to prevent code from shipping in the client for the purposes of hiding it?

#

or tO mAkE tHe sErVeR bUiLd sMaLl

glad badger
#

yeah. I'd like a separation of a few dlls that are meant only for client or server

undone coral
#

yes but to keep it secret?

#

like to prevent ordinary players from being able to run their own servers or inspect that code?

#

or for a different reason

glad badger
#

yeah its dedicated server code that doesn't get distributed

#

strict client-server arch

undone coral
#

okay

#

then your best bet is to use compilation defines

#
#if MYGAME_SERVER
class XYZ {

}
#endif
glad badger
#

there's a better way I just don't remember. using defines for an entire dll is not a good approach

undone coral
#

you can simply delete it after you've built the player

glad badger
#

scriptable build pipeline maybe? gah I don't remember

#

actually I think that was how I used to do it

jolly token
#

Does define constraints work for you?

jolly token
undone coral
glad badger
#

ah actually that might have even been it. just manually changing the define depending on the target I'm building at the time

#

thanks folks

jolly token
#

Yeah that will do

sleek terrace
#

My game crashes, when trying to load 1000 x 1000 tilemap,
anytips on what to do?

somber swift
fresh salmon
#

Yep, you can mark the method sealed and look for compiler errors

#

Sealed methods cannot be overriden, any override will now report an error

#

public sealed override OnServerAddPlayer

#

Okay next thing would be to use your IDE and find all references to this method, and go through them one by one

regal olive
#

Anyone ever messed around with 4d arrays before

fresh salmon
#

Ask your question directly

#

Don't ask if anyone knows XYZ, it's slower to get an answer!

#

No no

#

Your IDE's References

#

Not "Find this string in all files"

#

What code editor are you using?

#

Then right click on this one ^ (the function name) and select "Find all references"

knotty swallow
#

can someone give me reference on how to create methods like OnClick() that are being called when certain conditions are met? (not like if(foo == true){OnClick()})

fresh salmon
#

Well, looks good to me, the only reason you're not getting the log would be because the method isn't ran at all

#

Either in a base, or child class

#

No idea, I'm not familiar with that demo project, and networking altogether

sleek terrace
buoyant leaf
#

is it possible to have a VR toggle?

#

I'm planning on making a shooter game that can be played "normally" or using a VR headset

#

I'm thinking its a "simple" camera and character controller switch, but does changing the camera also change the outputs from a VR headset to a Regular screen?

sleek terrace
#

tilemap.placeBlock() is much slower than tilemap.setTiles()

if your tiles are < 10,000,
untested if more

glad badger
#

holy crap. I can't believe I never knew you could mark method overrides as sealed lol I thought that was only at the class level omg

dapper cave
#

SceneManager.LoadSceneAsync still causes massive hiccups in 2021... i don't think they'll ever fix that.

#

How do you guys load scenes without causing hiccups? and don't tell me assetbundle ๐Ÿ’ข

jolly token
dapper cave
#

before activation i mean

jolly token
dapper cave
#

no big deal, i remember that loadsceneasync behaves differently between editor and runtime... lemme test that

jolly token
#

Yeah maybe it's different from build

undone coral
#

Why are SystemInfo.supportsAsyncCompute and SystemInfo.supportsGraphicsFence false in the editor in dx12 with force-gfx-jobs native and true in the player with the same settings?

#

how do people use graphics fences in the editor?

#

is the answer, "no"?

jolly token
#

Nvm

pulsar tundra
#

Hi, im finding shortest arc between two Vector3s, however when their dot product is -1 there's an unexpected behaviour where my character rotates 360deg, I thought this code should counterract that?

gray pulsar
#

but also, doesn't Quaternion.FromToRotation do exactly what you want?

dapper cave
#

no big deal i remember that

chilly nymph
#

Hey gents, I never work with levels, what's the workflow for streaming in a full level, including baked lighting, and any other scene specific data?

#

I'm looking to stream in all assets not construct my level

devout orbit
#

Does anyone know how to add a cancellation token correctly to a async task?


        private async Task StartAcceptanceTimer()
        {
            try
            {
                await Task.Delay(TimeSpan.FromSeconds(AcceptanceTimer), cts.Token);
            }
            catch (TaskCanceledException ex) { }
        }```


Doing it like this now, but is it normal catch the cancellation? if I don't i receive a error log in my console.
I have a timer on a server and some things can cancel this timer.
undone coral
#

so is there no callback when the gpu has presented a frame?

#

seems so basic

#

how does IssuePluginEvent know which graphics buffer it was executed against?

#

it appears to be running immediately and not when a graphics command buffer is executed

#

does this make sense?

shy spruce
# shy spruce When loading scenes additively, is there anything special I need to do to get ev...

I found this which is where stuff like where OnMouseDown seems to get fired:

https://github.com/Unity-Technologies/UnityCsReference/blob/c84064be69f20dcf21ebe4a7bbc176d48e2f289c/Modules/InputLegacy/MouseEvents.cs#L173

And the trail seems to go dead here:

https://github.com/Unity-Technologies/UnityCsReference/blob/4d031e55aeeb51d36bd94c7f20182978d77807e4/Modules/InputLegacy/Input.bindings.cs#L287

I can't seem to find source for RaycastTry but it seems likely that it is only doing the raytracing in the container scene and not in the subscene. So I'm wondering if I need to add a camera to the subscene and switch the player to that camera after the subscene loads in...

Anyone had any experience with mouse events on colliders and multiple scenes?

undone coral
shy spruce
#

I can give it a shot. Do you know if it works on colliders across scenes?

chilly nymph
#

What framework do managed plugins need to be? <TargetFramework>net6.0</TargetFramework>

chilly nymph
#

<TargetFramework>2.1</TargetFramework> Correct?

chilly nymph
#

thansk

jolly token
#

No problem

chilly nymph
#

Any idea how to dotnet generate a 2.1 proj?

jolly token
#

You mean command line? dotnet build? dotnet publish?

chilly nymph
#

Commandline

jolly token
#

like iirc dotnet publish -o outputpath
then you get dll

chilly nymph
#

Just trying to generate the inital project with 2.1

#

Don't want to fuck around trying to scope the libs after switching from 6.0

jolly token
#

Oh you mean how to create 2.1 project for first time
dotnet new classlib --framework "netstandard2.1" -o MyLibrary

#

Something like that

chilly nymph
#

Dope thank you.

#

Hmmm... Unity is picking it up as a managed plugin, but I cant access it. Any ideas?

#

Is there a linker that auto connects with VS code? Or do I have to add the lib to my vs project as well?

jolly token
#

IDE? you probably needs to regenerate csproj

chilly nymph
undone coral
chilly nymph
#

Oh ffs

#

Plugins are now includeded wihtout having to import...

#

Is this new? Or am I missing something.

#

I have no using statements but I can access the plugin.

brisk pasture
#

using statements are not imports, you can always access stuff with fully qualified names

#

they might have just removed the namespace on it

chilly nymph
#

I should be able to state what namespace I want.

jolly token
#

Using is just to omit namespaces

#

Maybe your classes are not in namespaces? ๐Ÿค”

brisk pasture
#

if you want stuff in a namespace you have you manually wrap it in a
namespace Name { // your code here }

chilly nymph
#

Fuck, it looks like I have to restart VS each time I rebuild the plugin.

jolly token
#

so I just stick with copy-paste my plugin source ๐Ÿ˜Œ

#

Or use submodule

brisk pasture
#

if i am editing things alot, will just use a asmdef instead of compiling my own dll

jolly token
#

Also if you're using vs code there is reload command..

brisk pasture
#

rider is pretty good at detecting the changes and reloading it as well

chilly nymph
#

Thanks for the info!

#

I couldn't ever get into rider.

jolly token
#

I'm getting tempted to get one

brisk pasture
#

i work on multiple platforms, so made sense to use one that works on all of them

jolly token
#

VS code is supposed to be that cross-platform IDE ๐Ÿ˜ข

brisk pasture
#

am also familiar with the other jetbrains ide's make heavy use of CLion, GoLand and PyCharm too

jolly token
#

I'm up for any IDE but Eclipse family

brisk pasture
#

agreed

#

think i would forgo the ide and just use Vim before eclipse

chilly nymph
#

ONE final question regarding plugins, is it safe for a plugin to use Newtonsoft from nuget? OR is there another way I would do this?

#

What would be the proper way to use libs in my own lib for unity?

brisk pasture
#

unless you are distributing it as a package that can get complicated

#

Unity package manager lets you use com.unity.nuget.newtonsoft-json@3.0 as a dependency

#

otherwise i am not sure, if everything you need can be built into the dll its self it should be fine

#

but if it needs depednencies from elsewhere it can get more complicated

chilly nymph
brisk pasture
#

don't know off hand, would need to test

#

i have seen it get ugly with other plugins before, where they included there dependencies as dlls that might clash with other things

chilly nymph
#

So what would be the proper way to reference the unity version?

#

Download the lib from com.unity.nuget.newtonsoft-json@3.0?

jolly token
#

Yes use Unity package one

#

Oh itโ€™s compatible with NuGet one too

jolly token
chilly nymph
#

Interesting I'll try it out, thanks!

green ether
#

I have an advanced issue. Whenever I have an event defined in my code for OnCharacterControllerHit(), unity allocates 80 B of garbage EVERY FRAME. Whenever I comment it out, the allocation goes away. Is there any way to avoid this GC.Alloc? Or is this unavoidable when scripting within OnCharacterControllerHit()?

brisk pasture
#

got more details

#

what kind of event, like a C# event, a UnityEvent, just a unity message?

quartz stratus
brisk pasture
#

also the code invoking the event as well as subscriptions

green ether
#

yeah one sec

#

void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.gameObject.CompareTag("Bomb")) { var bomb = hit.gameObject.GetComponent<BombBehaviour>(); if (bomb != null) { bomb.InitializeBombKick(gameObject); } } }

brisk pasture
#

well right off the bat GetComponent allocates

quartz stratus
#

CompareTag is also costly, switching over to layers is the way to go if you're concerned about performance here

brisk pasture
#

a nice trick i have used before is cache both the collider and the component to a field on first hit

#

then on other hits, i first compare colliders if they are the same i use the component reference i already have

#

if not equal, then i save the new collider to the field and get the new component

#

have done this alot for raycasts that fire often, so i am not paying the full cost for a lot of hits to the same object

#

how is OnControllerColliderHit being invoked?

green ether
#

I use deep profile and it says that the method that is allocating the 80 B is CharacterController.Move_Injected()

#

it is being invoked when it the player runs into anything

brisk pasture
#

no like how by what

green ether
#

and specifically only calls the GetComponent when it collides with a "Bomb"

jolly token
#

Does GetComponent allocate? It should be just lookup

green ether
#

i dont believe it does

#

and it shouldnt be called every frame anyway

#

Especially when the player is standing still, because then OnCharacterControllerHit() is not being invoked

jolly token
#

ControllerColliderHit is class

#

Maybe that's what it is? lol

brisk pasture
#

really

#

would think that should be a struct

#

but yeah that could be a allocation unless they keep mutating the same one

jolly token
#

I wouldn't expect any optimization at the point they're using reflection ๐Ÿ˜Œ

brisk pasture
#

actully never used unitys own CharacterController always just rolled my own

#

guess stuff like Collision is also a class and so other unity messages act like this

#

does feel like it should all be structs thought

jolly token
#

To be fair they contains some lots of info to be struct

brisk pasture
#

in the case of ControllerColliderHIt mostly references to stuff that already exists

#

and a few vectors

#

guessing a reference is like 8 bytes

#

each vector3 would be 12

jolly token
#

so 40+36+4 bytes they have

#

Lol it is 80

brisk pasture
#

think i rather copy that much data then deal with that in gc

jolly token
brisk pasture
#

so the napkin math more or less proves it

#

really not sure how it can be avoided outside of not using the CharacterController

jolly token
#

Yeah only way would be not using that callback

brisk pasture
#

though i am really not familar with CharacterController

jolly token
#

I don't really use it too. It's too specific to be generic and too generic to be specific XD

brisk pasture
#

its a bit of work to make your own, but should be able to keep the allocs low to non on update

#

since we got all the NonAlloc raycast calls

novel plinth
#

Unity default characterController pretty much suck ass! Only useful for testing ๐Ÿ”ฅ

green ether
#

guess im gonna have to make my own then

#

i cant have 80 B allocations every frame

austere jewel
#

Please do not use gay in a derogatory way.

green ether
#

ok

jolly token
#

Does it actually effect your performance, tho?

green ether
#

I mean not really but i dont want 80 B allocations every frame

#

isn't something like that on mobile just bad?

#

Also with 100 players in a game that means that there would be 8000 B per frame

#

it adds up

jolly token
#

Well you wouldn't load 100 players at the same moment with physics.. are you?

austere jewel
#

GetComponent will allocate in the editor even if the result is null, because null can be a fake Unity Object in the editor for UnityEngine.Object types.
If you're checking the result of GetComponent with null you should use TryGetComponent instead

novel plinth
#

Adding to the above, CompareTag wont resulted in heap allocation anyway

jolly token
#

Well Generation-based GC is pretty optimized I believe

brisk pasture
#

also would worry about it when its a issue

green ether
#

doesnt help my gc.alloc problem but is still helpful

brisk pasture
#

need like a the more you know gif for that one

#

never knew TryGetComponent acted different memory wise

#

and i been using unity for a long long time

green ether
#

is there a better way to CompareTag() as well?

austere jewel
#

CompareTag is the best way to do it.
if you compare tags manually you inherit the cost of allocating the .tag string on the C# side.
(It also doesn't perform any checking whether the tag exists)

brisk pasture
#

i tend to not use tags at all

novel plinth
#

same

brisk pasture
#

in stuff like my raycasts i will get component for a interface type

novel plinth
#

its there for convenience only

brisk pasture
#

and do little trick to cache the result, along with its collider so i can do a comparison instead of getting component everytime

#

only get component again on a change of what is hit

shy spruce
#

Is there guidance on OnMouseEnter() style events that don't require an interface to be implemented versus IPointerEnterHandler.OnPointerEnter()? I believe the latter is the only that works with the new input system? I was not clear from the docs

brisk pasture
#

though will totally be swapping for TryGetComponent now that i learned about that extra detial of it

#

the interface way is the newer way

#

it ties into the same event system UI uses

#

its not related to legacy or new inputs system at all

shy spruce
#

Ah. The interface doesn't seem to work with colliders though yeah? Or perhaps it's because of my additive scene loading, which I'm kind of needing to use due to a Mirror networking consideration

brisk pasture
#

it does just needs more setup

#

you need a EventSystem if you have a canvas you should already have one

#

and the camera that sees the collider would need a PhysicsRaycaster on it

shy spruce
#

Okay yeah, have that, though it's in the "base" scene and not the additive scene. Let me add the raycaster and see what happens

brisk pasture
#

wont matter what scene the EventSystem is in

#

just make sure you only got 1

#

the Raycaster goes on the camera you are clicking from

#

there are 3 kinds a Graphic one for UI, a Physics and a Physics2d

shy spruce
#

Thanks @brisk pasture . You have solved the riddle

#

Had to add a Physics2DRaycaster

brisk pasture
#

it can be nice since it depth sorts

#

so UI can block a raycast to the world

orchid marsh
#

Hmm, my only concern with the component based filter is that you'd have to have specific components for every element of would-be tag and changing/managing components may be more if a chore than say.. switching a string tag or enum.

brisk pasture
#

@orchid marsh GetComponent works on interface types

orchid marsh
#

Which brings enum to the table with custom types to differentiate, which works.

brisk pasture
#

for example i got a IDamageable iterface

orchid marsh
brisk pasture
#

anything that can receive damage implements it

#

lets me not care about the exact component, just if it has the feature i need

green ether
orchid marsh
#

For instance, you no longer want said object to be a part of a group... with tags, your simply change it's value. With interface, you're going to need to removed said component and have variations without the specific interface to avoid being picked up by try get component.

jolly token
orchid marsh
#

Assuming you're now wanting to place the specified object into a different category that's not to be addressed with this function

green ether
#

can someone explain to me how 100 players each allocating 80 B of garbage every frame isn't bad? Not trying to be sassy i just want to understand why its not a big a deal as i think it is?

brisk pasture
#

is that a real usecase though?

orchid marsh
brisk pasture
#

we more questioned, if its worth the amount of work to make your own character controller

#

@orchid marsh was in context to AltTabbed

jolly token
brisk pasture
#

its to each there own, multiple ways to skin a cat

#

i do not know, but there is a #archived-networking room, your question might not scroll off the screen before someone sees it if put there

green ether
#

sorry, context is that each player will have OnCharacterControllerHit() defined

orchid marsh
green ether
#

which is whats causing the 80 B per frame

#

I found a simlar document online that talks about OnCharacterContorllerHit() allocating 80 B per frame

#

from 2 years ago

brisk pasture
green ether
#

I mean yeah thats what I'm saying

#

I don't know what giving OnCharacterControllerHit() a definition would start causing 80 B to be allocated

#

just weird

brisk pasture
#

no it makes sense

#

its hit data is 80bytes

green ether
#

why would it make sense for that to happen but not the same thing happening for OnCollisionEnter()

brisk pasture
#

for unity messages, it does not call them unless defined

green ether
#

or OnTriggerEnter()

jolly token
#

OnTriggerEnter just passes Collider

orchid marsh
#

Well the hit from cc is a class type with some actual allocations.

jolly token
#

Not sure about OnCollisionEnter, I think they would allocate too

brisk pasture
#

i think OnCollisionXXX has the same issues

#

might be less memory

#

OnTrigger is passing a reference to something that already exists

orchid marsh
#

I'm assuming Collision from OnCollisionXX just references other stuff (important data likely on the RB - thus requires an RB hitting it)

brisk pasture
#

Collision contains a lot of data about that collision though

#

not just things on a rb or collider

#

contains mostly reference types though

#

ah its like all getters

orchid marsh
green ether
#

ok I'm actually starting to understand why

#

very interesting.

#

So what I assume is occuring is the ControllerColliderHit class is being passed int OnControllerColliderHit() every frame, which explains why CharacterController.Move_Injected() is allocating 80 B of garbage every frame

#

sorry

#

is there any way to get OnCollisionEnter() to work with a character controller?

orchid marsh
#

Have an rb on a child object with collider at it's level or below. Parent would have the Character Controller.

green ether
#

The way I used to have it coded was that OnCollisionEnter() was defined on the "Bomb" objects that were kicked around, and it would work fine. But when I switched over to a character controller, it stopped working

brisk pasture
#

you are not going to like the normal way of makign a character controller from scratch

green ether
#

:(

brisk pasture
#

more lots of short capsule or raycasts in the direction of movmement

#

so you can early out and not move, if they hit something

green ether
#

I feel like theres gotta be anotehr way aroudn this

#

would unity hate it if I put another collider on

#

just for fun ๐Ÿ‘‰ ๐Ÿ‘ˆ

chilly nymph
#

Any ideas why GetWindow would be returning null on a Editor window?
var tempWindow = (ConfirmWindow<Category>)EditorWindow.GetWindow(typeof(ConfirmWindow<Category>), false, $"Delete ");

austere jewel
#

I doubt you can create a generic window

chilly nymph
#

It took some hacking but I got it...

echo star
#

Could someone please help me figure out how to formulate this. Given a float x, I need to determine if the object is facing up or down.

#

Face From To
Down -450 -270
Up -270 -90
Down -90 90
Up 90 270
Down 270 450

#

(please mind the formatting - I know there is a simple solution to this, but it makes my brain hurt)

orchid marsh
#

Looks like a negative sine wave

#

Where a period between [0, 360]

#

Would have it changing states (slopes) at```cs
000-090 (down)
090-270 (up)
270-360 (down)

#

It'd be the negative sign wave

#

Where pi would have been 180

#

pi/2 at 90

#

and 3pi/2 at 270

#

2pi at 360

uneven star
orchid marsh
#
bool isUp = ((int)Mathf.Abs(x + 90) / 180 + 1) % 2 == 0;```
uneven star
orchid marsh
#

What were not told is if 90 is up or down

#

As the example had it with both ranges but did not state whether it was inclusive or exclusive.

echo star
#

Thank you. I am trying to follow along but this problem makes me feel really dumb haha. The Mathf.Repeat seems to work. The IDE complains when I try to assign -1 * (Mathf.Abs(x - 90) / 180 % 2); to bool

orchid marsh
#

result == 0, Edited.

gentle gate
#

Hey guys, I would appreciate it if someone could tell me how to detect edges using raycasts like in Marvel's Spider-Man (Web-Zip) and Batman Arkham (Grappling Gun) games, I've been strugling with it for a very long time.
Thanks.

sinful gale
gentle gate
#

thanks, but i've already done it

#

i used 3 raycasts
first one casts from the camera
second one casts up from the first ray's hit point
third one casts down from the second ray's hit point and with a little bit of forward offset
and i used a capsul overlap to check if the ledge is suitable for the player

#

i suck at explaining, sorry

#

yea

#

alot

#

still struggling

#

it's saying that the ledge is not vertical but it is

#

that's true

#

it is?

unborn lava
#

How to use GetComponent dynamically.
Instead of writing ``` webSocketMenuServer.GetComponent<MenuServer>().rq_tcpid();

I can write something like
    webSocketMenuServer.GetComponent(scriptName).rq_tcpid();
fresh salmon
#

GetComponent has an overload that isn't generic, and that expects a Type argument.
Better solution, make the scripts you want to access implement an interface, and GetComponent that interface instead.

#

It'll return the first attached type implementing said interface.

unborn lava
#

To be honest I didn't really understand your solution

fresh salmon
unborn lava
#

Yes I know

fresh salmon
#

Alright so GetComponent can take interface types GetComponent<IMyInterface>(), and it'll return the first script that implements the interface.
So the proposal would be to make all scripts that are supposed to be fetched with that GetComponent, implement this interface, so one GetComponent can get different scripts

unborn lava
#

Ah ok now I get it. I will give it a try

#

Thanks for your help

plucky sparrow
#

Hello so I am working on a first person script and I got everything to work 100% of the time but jumping. What happens is whenever I slid and jump my character flies into the sky (3-D btw). I have changed the gravity to -30 -20 and -10 but whenever I got to 0 or 10 I drift into the sky. I checked the code and even replaced the code many times now to see if it was the problem but it doesn't seem to be the issue. It has to do something with how the code works with gravity but I don't know. Any Ideas? (going to get code)

#

this is everything to do with jumping and gravity

#

I think

plucky sparrow
#

my bad

storm maple
#

Hey I have a function that takes TerrainData and sets large arrays of data to ComputeBuffers (data about grass positions), it takes around 16ms, and is a one time thing (only called once, when chunk is generated). What is the best way to call that function and wait for it to finish without making the game stutter?

#

Could it be turned into an IJob? I haven't worked with the job system, so I want to ask first

#

ok i will look into trying that

rugged radish
storm maple
rugged radish
#

and data would need to be split into chunks too

storm maple
#

yes that i know, but i haven't worked with jobs or coroutines ever (i am coming from c++ ๐Ÿ’€ ) so i have to look up the implementation

#

but does copying to the gpu memory halt everything else?

#

like i mean in rendering

rugged radish
#

also, if you only need some point field on the gpu for geometry shader stage, you can take a look at tessellation stage
I use that to render grass fields
for the initial setup I was also sending point distributions into the shader

storm maple
#

what is the performance like? i am doing very fine with DrawMeshInstancedIndirect ๐Ÿ˜„

rugged radish
#

yeah, I heard that too, until I came across a talk by Ghost of Tsushima devs
they use it extensively

#

I'd say performance is great, but I haven't actually tried to run it on a mediocre device

storm maple
#

I might look into it in the future, thanks for the info

#

what are you working on?

#

that requires grass

rugged radish
#

But if but Ghost of Tsushima runs on consoles, I'd imagine you can make performance good

storm maple
#

Yeah, makes sense

hardy nymph
#

Hi I needed some way to run unity functions in Editor script, from another thread.

silent jungle
#

ok so I think I figured out drawmeshIndrect well enough and got some results, but I encountered something that I cant wrap my head around; I have 3 meshes that are being drawn :

 for (int i = 0; i < LODMeshes.Length; i++){
            MeshMat.SetBuffer("_ChunkData",LODBuffers[i]);
            MeshMat.SetColor("color", colors[i]);
            Graphics.DrawMeshInstancedIndirect(LODMeshes[i], 0, MeshMat, MeshBounds, ArgsBuffer, i * 5 * 4);
        }

But only the last batch gets rendered to the screen, after some investigating, I found that if I only do one draw call of a particular buffer and mesh, it renders correctly, but when I have it in this for loop it does not

hardy nymph
#

I need some way to run the getData () function inside the socket events, but socket events are handled on a different thread.

#

and note, this is an editor script

undone coral
hardy nymph
#

This is the full code

hardy nymph
#

don't know about that , let me search

#

will that work in editor script ?

#

in the edit mode

undone coral
hardy nymph
#

yes

undone coral
#

yeah

hardy nymph
#

alright let me test it

undone coral
#

it really depends what your goals are

#

it's automating the editor remotely right?

#

through a web interface?

uneven star
undone coral
silent jungle
uneven star
unborn vessel
#

Hello, i have a really advanced question. How would i be able to create runtime modifiable language/script or whatever. Basically i want a text file that you can type in stuff like Cube1 : Cube { position = new Vector3(0, 0, 0)} and so the game reads the file and for example gets the position of the cube1 and instantiates it in the position given in the text file. I'm looking for resources so i could start on this, i haven't really found anything useful on the internet (or i just can't look properly)

#

Also i forgot to tell you that the text file should be accessible in the built version of the game so when i build the game others can modify the text file

devout hare
#

If you just want to place objects and set their properties, that's basically the same thing as loading in a save file. There are plenty of resources for that.

#

I know. It's basically the same thing as loading in a save file.

unborn vessel
unborn vessel
undone coral
#

it's robust

#

the text file would be a lua script

spice ocean
#

Is there a way to disable the profiling of a specific code block?

unborn vessel
#

So to add to the topic i want like a text based map editor so there can be Cube1 : Cube { position = new Vector3(0, 0, 0); scale = //define my scale etc.} Cube2 : Cube { position = new Vector3(10, 4, 1); scale = //define my scale etc.}

undone coral
devout hare
#

There are plenty of tutorials also for saving and loading level data, you'll only need the loading part of that

#

a full scripting language would be overkill if you don't need actual scripting

undone coral
unborn vessel
# undone coral you can use moonsharp

I've heard of it but can it access c# scripts? Since the Cube that it's inheriting from has all the values that the textmap is setting and also all the functions.

jolly token
#

Yeah that looks like just some config file can be done with json or yaml

undone coral
#

i kind of want to just turf this patient

undone coral
spice ocean
#

My sockets send methods are allocating garbage, so i whant to just ignore them at the profiler, is there a way to do it? (this is until i create my own native udp socket implementation of course)

unborn vessel
undone coral
#

what do you mean ignore them at the profiler? the unity profiler? it will not create a span (technical term for a "Begin Sample" "End Sample" pair) unless deep profiling is turned on or you explicitly sample it

undone coral
#

why not just edit in unity

#

for 1 user, you

hardy nymph
spice ocean
unborn vessel
solid notch
#

do anybody knows how to fix this error

#

i get this error while building the project into apk

solid notch
undone coral
#

try restarting your computer

solid notch
#

ok i will try

jolly token
#

Like PyPy

unborn vessel
#

Yeah i know how those things work. That was fully a joke, why would i create a game engine inside unity.

#

Using a game engine like unity is really good too because you skip like 5-10 years of learning programming in languages like C++ and another ~5 years of the engine development

#

It uses Mono for the C# stuff right?

#

Sorry Unity admins to be going off-topic of Unity but before i'm trying to write a game engine i'd rather make a simple Asteroids style game in Raylib or something to learn the basics of C++

quartz stratus
#

Yeah, this is so so annoying.

#

That might be part of the reason while I usually end up scrapping my interfaces (๐Ÿ˜ข) and trying to accomplish the same goal with abstract classes. Not the same though.

#

From someone on Unity Answers:

"By definition serialization of an interface makes no sense because serialization is storing the state of the data of an object and Interfaces have no data.

Similarly, "inspecting" an interface makes no sense because the inspector displays the data, which an interface does not have.

If you have sub-classes that share data you should use an abstract parent class. You can use custom inspector inheritance to share inspectors."

They actually raise some fair points lol. Oh well.

#

Still would be nice, just for designers working in Unity at least.

#

Just for like restricting what can be assigned to a slot, and nothing more.

jolly token
#

Haven't tried myself but I think you would be able to work around with custom inspector like
[OnlyAccept(typeof(IMyInterface))] public MonoBehaviour component
Probably

quartz stratus
#

I mean... I think they have their answer: no.

#

Lol

jolly token
#

I'm going with DI Container ๐Ÿ˜„

quartz stratus
#

It's not like it's unspecified behavior. It's a non-bevahior xD

#

Yes precisely. It really does remind me of how Unity is continually behind C#. And not just on newer features but fundamental ones like interfaces as well.

idle saddle
#

does anyone know how I fix this? I got these build errors when trying to build my project to webGL

autumn topaz
#

NVM found the solution, you just have to make a new URP renderer for cameras making render textures

chilly nymph
#

This is a little bit hacky but it's what I have to do in order to get generic properties working in my window,
TL;DR I want to deconstruct a object with reflection then reconstruct it back with some data without using generics
I take a object break it down to it's properties, then collecting the data generically then I want to reconstruct it into it's original type:

        public void Set(Data dataObject)
        {
            data = dataObject;
            var propertyInfos = dataObject.GetType().GetProperties();
            genericLabelObjects = new GenericLabelObject[propertyInfos.Length];

            for (int i = 0; i < propertyInfos.Length; i++)
            {
                if (propertyInfos[i].GetIndexParameters().Length == 0)
                {
                    genericLabelObjects[i] = new GenericLabelObject(propertyInfos[i].Name, null, propertyInfos[i].PropertyType.Name);
                }
            }
        }

Lets say I pass my Set a public class Item : Data this Set function takes all the properties and puts them into a custom label, from there I can edit them, what would you guys do to get the data in the GenericLabelObject back into a Item object? Can you see a good solution to setting the data back into the Item?

jolly token
chilly nymph
#

Iterate through the properties of the original Data then set the values with the keys?

#

How would I be able to say it's an Item?

#

Without Generics?

jolly token
#

You can get specific property by the name

#

You are already have property name, type wouldn't matter

chilly nymph
#

This is for the object itself, not the properties.

hollow rapids
#

And isn't he getting the type in the dataObject.GetType()?

jolly token
#

Are you asking how to get a new instance of Item?

chilly nymph
#

I need to pass a new instance of the passing type.

Serialize.SetJson<Item>(data)

#

Item In this case being what I'm trying to construct.

#

If I pass my Set a Foo then Serialize.SetJson<Foo>(data)

#

I'm just looking to re construct my original Data back into the type I passed initially.

#

Without using generics.

jolly token
#

Well you need a Type at least then you can use Activator.CreateInstance

chilly nymph
#

I don't think I can pass it typeof can I?

hollow rapids
#

Serialize.SetJson<data.GetType()>(data) Shouldnt this work?

jolly token
#

No that's not how generic would work ๐Ÿ˜…

jolly token
chilly nymph
regal olive
#

I'm using an asset UniStorm with URP URP 13.1.8 on 2022.1.16f and I get this error
error CS1503: Argument 1: cannot convert from 'UnityEngine.Rendering.Universal.RenderTargetHandle' to 'UnityEngine.Rendering.RTHandle'
error CS1503: Argument 2: cannot convert from 'UnityEngine.Rendering.Universal.RenderTargetHandle' to 'UnityEngine.Rendering.RTHandle'

The line is

copyDepthPass.Setup(RenderTargetHandle.CameraTarget, RenderTargetHandle.CameraTarget);```

full function:
```csharp
    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        if (!settings.isEnabled)
            return;

        // UniStormAtmosphericFog Pass
        fogPass.settings = settings;
        fogPass.Setup(renderer.cameraColorTarget); //, renderer.cameraDepth);
        renderer.EnqueuePass(fogPass);

        // CopyDepth Pass
        if (Application.isEditor && !Application.isPlaying) return;
        copyDepthPass.Setup(RenderTargetHandle.CameraTarget, RenderTargetHandle.CameraTarget);
        renderer.EnqueuePass(copyDepthPass);
    }

simply changing it to RTHandle. does not work it tells me it doesn't exist in the current context. I think maybe because it has to be setup/initialized?
Not sure if this is considered advanced, can move if needed.

I joined the developers discord and there was someone who asked a month ago with no response.

chilly nymph
#

Thoughts on this: newInstancePropteries[i].SetValue(newInstance, Convert.ChangeType(genericLabelObjects[i].value, newInstancePropteries[i].GetType()) );

I'm not seeing how I can get past the dynamic casting:
InvalidCastException: Invalid cast from 'System.String' to 'System.Reflection.RuntimePropertyInfo'.

#

All my values in my constructed data are strings

orchid marsh
#

Where -sin is that of the sine wave but with a negative slope.

#

where -sin would be equal to sin(x + pi).
cos would be that of sin(x + pi/2)

jolly token
#

Ah I see where you got wrong idea. newInstancePropteries[i].GetType() is type of PropertyInfo

chilly nymph
jolly token
chilly nymph
#

Thanks mate!

                    for (int i = 0; i < newInstancePropteries.Length; i++)
                    {
                        newInstancePropteries[i].SetValue(newInstance, Convert.ChangeType(genericLabelObjects[i].value, newInstancePropteries[i].PropertyType));
                    }
undone coral
undone coral
#

might as well do it with moonsharp

undone coral
#

there are 0 new features for you in 2022 for URP

undone coral
#

i don't have my editor open so i don't kow exactly what it's called

autumn topaz
orchid marsh
#

Don't cross post

gilded shuttle
#

lol discord mod wannabe

undone coral
humble leaf
dusky tiger
#

Hello Im getting this erro Deterministic compilation failed. You can disable Deterministic builds in Player Settings Library\PackageCache\com.unity.multiplayer-hlapi@1.0.4\Editor\Tools\Weaver\AssemblyInfo.cs(22,28): error CS8357: The specified version string contains wildcards, which are not compatible with determinism. Either remove wildcards from the version string, or disable determinism for this compilation

#

does anyone know how to solve it ?

unborn lava
#

var webSocketMenuServer = GameObject.FindWithTag("WebSocketMenuServer");
webSocketMenuServer.GetComponent<MenuServer>().Invoke("rq_tcpid", 0);

#

I try to call a function using a string name

#

but it doesn't seem to work

chilly nymph
#

Can anyone see why this isn't removing the object?

        public static void DeleteItem<T>(T data, Path path)
        {
            if (DataStore.HasFile(path))
            {
                var dataCollection = Deserialize<T>.GetJson(path);
                dataCollection.Remove(data);

                var json = JsonConvert.SerializeObject(dataCollection);
                File.WriteAllText(DataStore.GetFilePath(path), json);
            }
        }
chilly nymph
dusky tiger
# chilly nymph You googled it?

yes it said that I should do sth with multiplayer HLAP but didnt find it only found multiplayer HLAPI but then it said that I should click up to date but cannot find it

chilly nymph
chilly nymph
# dusky tiger

It tells you the error mate: You can disable Deterministic builds in Player Settings

dusky tiger
#

what is player settings

chilly nymph
unborn lava
chilly nymph
dusky tiger
#

@chilly nymph thanks fixed it ๐Ÿ™‚

jolly token
#

Did you implement IEquatable<T> or override Equals?

brisk pasture
chilly nymph
jolly token
#

Yes

jolly token
chilly nymph
jolly token
chilly nymph
#

I understand what's going on. That's not the issue, I'm just looking for a way to reference in the proper way.

#

.Convert for this again?

jolly token
#

So it's not going to remove anything because there is no same data in there

chilly nymph
jolly token
#

Because there is no equality check logic given

#

so it just trying to check with "pointer address"

chilly nymph
jolly token
#

data is already created before you call DeleteItem
They are not same element

chilly nymph
#

Ah.

#

Sorry I was being a retard, I understand, what's the best way to get a reference to the data?

jolly token
#

So since you are doing serialization you cannot 'recover' actual reference to data

#

But for this use case you can implement IEquatable<T> or override object.Equals

brisk pasture
#

you would have to make sure your type has its own way to test equality

jolly token
#

To provide custom equality check

brisk pasture
#

does not do the same thing, but other approach would be pass a delegate in as a selector

#

that way you can choose a field or something to select on

#

or you could constrain the data to just structs

#

so its not a reference in the first place

jolly token
#

Or, you can perform PopulateObject to your original data

#

So your original data get overwritten, instead of creating new objects

chilly nymph
#

What about construct the set again but with out the data I don't want? It's heavy...

#

^^ That may work.

#

Thanks lads

brisk pasture
#

to me its kinda weird a remove function is Deserialize and doing a Serilize

#

would think Deserialize would happen eariler and you just hold on to the data in memory and modify it as needed

chilly nymph
#

Yeah just piping in the logic will move it over.

#

It needs to deserialize the original json to remove what it needs, I don't keep this in memory. .

brisk pasture
#

where does the object you are removing come from?

chilly nymph
#

Json

brisk pasture
#

from the same json?

chilly nymph
#

It desseralizes the data then I need to remove an element then write back to json.

brisk pasture
#

i am talking about the item you are asking it to remove

#

where does it come from?

undone coral
chilly nymph
brisk pasture
#

from the same json file?

chilly nymph
#

Yes

#

read-> remove -> write.

brisk pasture
#

then why are you deserialize, to find the object to remove, then doing a deserialize again to do the remove

chilly nymph
#

?

#

I'm deserilizing once.

jolly token
#

He's asking where the data is coming from

chilly nymph
#

dataCollection.UnionWith(Deserialize<T>.GetJson(path));

undone coral
#

if you need to remove a field from json, you can read it as a JObject, delete the field, then write it back

#

you do not need to interact with strong typing at all

brisk pasture
#

i am asking where data comes from

chilly nymph
#

I guess I could construct my data as a JObject.

#

But it's pretty much the same thing.

chilly nymph
brisk pasture
#

well if it came from the same place you are trying to remove it from, you are doing way more work then required

#

and making it a more complicated issue then it is

chilly nymph
#

How so?

brisk pasture
#

if its something you constructed yourself, then that is different

chilly nymph
#

It's a CRUD system

#

This is a delete function.

#

๐Ÿ˜„

#

I need to be able to delete data.

brisk pasture
#

because of the reference equality and it not having the same identiy

#

if you want the comparison to be by value, you will need to tell it how to compare equality or will need to not use a reference type

#

like use structs instead

#

since its not working because the exact instance of data you are passing in does not exist in that hashset

chilly nymph
#

Yeah I was just being a dumbass, was thinking I could get a free Remove out of the collection.

jolly token
#

If you use C# record type and it gives you free Equality check ๐Ÿ˜„

#

Not sure it will work well with Unity, tho

brisk pasture
#

if the type contains a id, you could also just compare on that

chilly nymph
chilly nymph
brisk pasture
#

well define what you count as equal

chilly nymph
brisk pasture
#

but you don't, based on your problems

chilly nymph
#

Dude, the problem was understood like 10 min ago.

#

C# isn't my native language, as soon as Cath said pointers I understood.

#

We're way passed what you're tyring to explain. ๐Ÿ˜„

undone coral
#

๐ŸŒˆ

chilly nymph
#

Jobject has remove, thabks for the advice gents!

grave vortex
#

This is a double post from shaders as well. I'm trying to work out an idea for a skybox around a tiny planet. I've been stuck on it for a while. Has anyone done something similar or have an idea that I could try? Thanks.

sudden owl
#

is it common for tilemap state around a tilemap position to be stored as a string representation of binary?

unkempt nova
#

No

austere jewel
#

"string representation of binary"? Sure, it's common enough to save all sorts of things as bit flags. But what do you mean about the string part, literally "00111100"? It would defeat the point if you saved that as a string

#

If you wanted to transfer that as a string for human-in-the-middle reasons you could use hex ("3C") , or if you had a whole bunch of it, base64

sudden owl
#

I've been studying roguelikes and procedural map generation lately. Cellular automata is next on my list after I'm done with these tutorials https://youtu.be/szOq1HSWtm0

In this episode, he's taking an approach that I am at first a little skeptical of... but maybe it's fine. I'm not sure yet.

Learn how to procedurally generate a 2D dungeon in Unity using Random Walk and Binary Space Partitioning algorithms! In this tutorial we will use unity Tilemaps to create single and multi room dungeons connected by corridors using Corridors First and Rooms first approaches.

Resources
https://github.com/SunnyValleyStudio/Unity_2D_Proecdural_Dun...

โ–ถ Play video
#

He's looking at all the tilepositions around the current tile in a foreach loop, and building a string representation of 1=floor 0=not a floor

austere jewel
#

Just at a glance there's some bizarre stuff going on as far as I'm concerned. A hashset of bitmasks that is used as a helper is weird as hell

#

These things should just be enums, which has the added benefit that you can't just come along and directly modify it from anywhere

sudden owl
#

Right, I was like... surely there's a more standard way of doing this..

#

is it for performance reasons or what?

austere jewel
#

Yes, for performance reasons. Strings are immutable, so any time you operate on a string that will allocate a new string

sudden owl
#

right so his approach is actually not performant

austere jewel
#

so in this foreach loop (presumably 9 directions) that's 9-ish strings being created and thrown away. Small, but if that's used often enough it'll contribute to GC

sudden owl
#

to his defense, the algo only runs once when the scene loads, so... yeah

austere jewel
#

It should all just be enum flags and literal bit operations. But I presume he didn't want to teach binary logic?

sudden owl
#

he did mention powers of 2 for the binary positions but hasn't used the concept yet

austere jewel
#

Or maybe he wanted it to be able to scale out to not be binary, and eventually just have any letter represent a different tile type

#

which is also weird to me, but less bad than just doing what should be a traditional bitmask

sudden owl
#

I'll finish the video series but at this point I am going to hold off on typing every line manually like I have been doing since the start.

#

I'm trying to understand all of the code without just downloading it from GitHub.

#

I've made a few changes along the way

austere jewel
#

If you're learning I think it's fine to just view most things as experiences to pick up, not even correct experiences, just as long as you're doing something that you think about, you're learning

sudden owl
#

yeah, I have compiled a list of like 10-15 videos on this subject that I thought were really good, really advanced. Prim's algo, MSTs, A*, Random Walk, Cellular Automata, and more.

austere jewel
#

If you want an overview of how it might work if you had an actual bitmask, which could be a single byte I have a little overview that should be familiar enough if you're doing similar things: https://help.vertx.xyz/info/bitmasks

sudden owl
#

bitwise operators

chilly nymph
#

This is the most disgusting thing I've written in a long time:

        public static void DeleteItem<T>(T data, Path path)
        {
            var obj = JsonConvert.SerializeObject(data);
            JObject remove = JObject.Parse(obj);

            using (StreamReader file = File.OpenText(DataStore.GetFilePath(path)))
            {
                string json = file.ReadToEnd();
                JArray array = JArray.Parse(json);
                JToken token= new JObject();
                foreach (var item in array)
                {
                    if (JToken.DeepEquals(remove, item))
                    {
                        token = item;
                    }
                }
                array.Remove(token);
            }
        }

Please tell me there's a better way.

hollow wing
#

hey guys, both the other chats are super dead tonight. was wondering if you knew a way to disable the physics of a box collider but still get the collision detection for it. Basically I built an in house renderer to draw close objects, medium objects, and far objects but my camera seems to skip anywhere from 45 degrees to 90 degrees sometimes randomly. My assumption currently is that I'm colliding with an object and getting thrown.

#

also should say my detection box for drawing is a very large box collider

hollow wing
#

awesome thanks, ill check it out

pliant crest
#

like the simple alternative would be just save the whole object later back to disk

#

instead of dynamically trying to update it like that

#

cause theres no benefit from doing this

chilly nymph
chilly nymph
pliant crest
#

of doing it the way you are doing it

chilly nymph
#

What are you talking about mate. This is how I have to do it. ๐Ÿ˜„

pliant crest
#

i mean over the way i mentioned

chilly nymph
#

What way did you mention?

pliant crest
#

or the normal way

#

just save the whole object

#

and override the json

#

instead of trying to take sections

chilly nymph
#

It's a delete function mate.

pliant crest
#

i know

#

what about it?

chilly nymph
#

I need to grab the item to delete from the json.

pliant crest
#

no thats backwards thinking

chilly nymph
#

I don't have any references to any data.

pliant crest
#

why would you need to do that

chilly nymph
#

Because I need to get the object from json.

pliant crest
#

but think about this from a concept point of view

#

its just saving data

chilly nymph
#

No it's not.

pliant crest
#

whether its delete or not

#

you are just saving data

chilly nymph
#

It's getting the data, then deleting the specific object from that data.

pliant crest
#

then what do you do with that data?

chilly nymph
#

What does it matter?

pliant crest
#

cause that changes why this is necessary or not

chilly nymph
#

This is a delete item function.

pliant crest
#

well

#

you are being stubborn

#

i have no stake in this

#

so up to you

chilly nymph
#

Thanks.

untold moth
#

Since a native array is a struct, does passing it by value breaks it?๐Ÿค”

#

I'm getting an error saying that I'm trying to access a disposed array. Trying to figure out wether it's due to passing it into another method or because I misunderstand the lifetime of an array retrieved with async GPU access...

orchid marsh
#

I'm guessing you've tried to reference it and are getting that error?

pliant crest
#

it kinda depends on when the other method runs i guess?

#

cause passing it by value doesn't copy it

#

since its a native array

#

when one gets disposed every one of them dies

orchid marsh
#

What's the exact error?

untold moth
#
ObjectDisposedException: The UNKNOWN_OBJECT_TYPE has been deallocated, it is not allowed to access it Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <823fb226a3f9439cb41fdcb61f9c86a1>:0)

Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <823fb226a3f9439cb41fdcb61f9c86a1>:0)

Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <823fb226a3f9439cb41fdcb61f9c86a1>:0)

BuilderGods.Terrain.EdgePathGenerator.GeneratePath (System.Int32 firstNodeIndex, Unity.Collections.NativeArray`1[T] edgeInfoArray, System.Collections.Generic.List`1[T] remainingNodes, System.Boolean looping, System.Threading.CancellationToken ct) (at Assets/Scripts/TerrainSystems/EdgePathGenerator.cs:138)
#

Added a bit of callstack for context.

#

From the look in the debugger it seems to have the same pointer and other properties before and after passing it to the method, so I'd assume that copying it is not the issue. It's probably something with Async gpu access and me trying to process several arrays at the same time.๐Ÿค”

pliant crest
#

its whether or not it gets disposed during its access lifetime

untold moth
#

Yeah, that's what I'm wondering. When would it be disposed? Does it only exist for 1 frame?

pliant crest
#

depends on whats managing the resource

untold moth
#

Hmm... Async gpu acess?

#

I'll try to copy the data into a regular array right when I get it.

#

Seems like it was it.

#

I guess the issue is that I was passing it into an async task. It was probably being disposed on the next frame which caused the issue.

austere jewel
#

Native collections should always be manually disposed. Presumably what allocated it is disposing it?
Depending on the type of allocation there's also rules on how long the allocation can live for

rugged radish
#

yeah, async gpu readback result exists for just one frame, need to copy the entire result on the same frame you get it

hushed moth
#

in the WebRTC, the video receive sample is setting the raw image's texure all the time. That is taking a lot of resources and may not work with 4K. Is there a better way to do it?

undone coral
undone coral