#archived-dots

1 messages Β· Page 79 of 1

mint iron
#
public unsafe struct StaticPointer
{
    public void* Pointer;

    public static T* Create<T>(T value = default) where T : unmanaged
    {
        var instance = new StaticPointer();
        var size = UnsafeUtility.SizeOf<T>();
        var align = UnsafeUtility.SizeOf<T>();
        instance.Pointer = UnsafeUtility.Malloc(size, align, Allocator.Persistent);
        UnsafeUtility.MemClear(instance.Pointer, size);
        T* typedPointer = (T*)instance.Pointer;
        *typedPointer = value;
        return typedPointer;
    }

    public T* As<T>() where T : unmanaged => (T*)Pointer;

    public T GetValue<T>() where T : unmanaged => *(T*)Pointer;

    public ref T AsRef<T>() where T : unmanaged => ref *(T*)Pointer;
}
trail burrow
#

@mint iron burst supports generic static methods right ye?

mint iron
#

yeah

#

kinda of

#

the generic has to be in the method rather than containing class

#

which is probably why their TypeHelper<T> is still a class and blocking any kind of entity create/destroy while inside burst

trail burrow
#

@mint iron yeah, that's what i mean - all my generic methods are void Bar<T>() not Foo<T>.Bar (in a type)

mint iron
#

yeah thats fine

amber flicker
#

I have e.g. ComponentDataFromEntity<Bob> bobs; set in an IJobChunk - to try and avoid a somewhat expensive bobs.Exists(entities[i]) I wanted to set a simple bool: bool hasBob = chunk.Has(BobType) - the problem being that BobType and the CDFE are declared both type Bob so Unity throws an error thinking the job uses the same type in different ways. One way to get round this is to use multiple entity queries and set the property in update instead but it would be nice if I could avoid that - any thoughts?

amber flicker
#

Just using .Exists in the first iteration of the chunk works for now πŸ‘

lyric gust
#

I like what you do @trail burrow

trail burrow
#

? πŸ˜ƒ

lyric gust
#

perhaps I'll use an unsafe structure in my asset

#

any kind of speed increase is always appreciated

trail burrow
#

collections are not done yet

#

but have everything except HashSet<T> now

lyric gust
#

I use a lot of HashSets to run my coroutines

trail burrow
#

Array, Heap, Dictionary, List, MemoryPool, Queue, RingBuffer, Stack - List/Queue/Stack are also available in 'fixed size' versions (i.e. where they can't expand)

lyric gust
#

and some dictionaries

#

what about base arrays?

trail burrow
#

oh and two concurrent queues also, one SPSC and one MPSC

#

@lyric gust yeah UnsafeArray

lyric gust
#

do you know how much faster an unsafe array is than a safe one?

trail burrow
#

that's not the point of them tho

lyric gust
#

does it index faster, or just alloc faster?

trail burrow
#

the point is that they are compatible with ecs components/other struct-pointer based systems

#

that can't deal with managed arrays or even NativeArray<T>

lyric gust
#

I thought ecs could deal with NativeArrays

trail burrow
#

@lyric gust you cant put a NativeArray<T> on a component

#

for example

#

and you cant take a pointer to NativeArray<T>, etc.

lyric gust
#

that... sounds inconvienient

#

I'm trying to wrap my head around ecs, still haven't built something in it

#

but the examples use native arrays a lot

trail burrow
#

@lyric gust yes but try to put a nativearray on an ecs component

#

It won't comply

lyric gust
#

so the ecs framework passes you a native array, but you can't create a local variable of that type?

#

the only way to use local collections is to make them unsafe.. is that right?

lyric gust
trail burrow
#

@lyric gust yes ofc you can

#

But you can't store them on a component

lyric gust
#

ahh.. ok

#

but you can store an unmanaged array?

worn stag
#

Got NativeArray has been deallocated error when trying to add entities to the nativelist

public class InventorySystem : ComponentSystem
{
    public NativeList<Entity> items;
    
    EntityQuery someGroup;

    protected override void OnCreate()
    {
        var query = new EntityQueryDesc
        {
            All = new ComponentType[] { typeof(ItemComponent) }
        };
        someGroup = GetEntityQuery(query);
        
        EntityManager entityManager = World.Active.EntityManager;
    }

    protected override void OnUpdate()
    {
        Entities.With(someGroup).ForEach((Entity entity, ref NameComponent r) =>
        {
            Debug.Log(r.Value);
            
            items.Add(entity);
            //Debug.Log(items[0]);
        });
    }
}

what am i doing wrong?

tawdry tree
#

Uhm, are you ever initializing the nativearray?

worn stag
#

oh thanks

#

public NativeList<Entity> items = new NativeList<Entity>(100, Allocator.Persistent); fixed error

tawdry tree
#

Yeah, that

worn stag
#

its like second day i learning ecs, sorry for stupid questions

tawdry tree
#
public NativeArray<Entity> Entities; //Declaration. 'This variable should exist'

void SomeMethod(){
  Entities = new NativeArray<Entities>(); //Initializing. Doesn't ACTUALLY exist before this!
}
#

I'd say that is more of a general programming thing, but I've made sillier mistakes πŸ˜›

#

By the way, are you sure you need that to be persistent, ie. last over multiple frames?
Just checking, because you should avoid making persistent nativecollections unless you need to.

worn stag
#

its doesnt work with Temp or TempJob or without allocator... same NativeArray error

#

so i think Persistent is my way?

tawdry tree
#

You need to declare it in the OnUpdate method if you want it to be temporary, I think

worn stag
#

oh its not working even with Persistent now

#

what a mistery

#

a will try in OnUpdate

#

it worked few minutes ago tho

tawdry tree
#

so

void OnUpdate(){
  var entities = new NativeArray<Entities>(Allocator.TempJob);//Like so
  //Use as needed
  entities.Dispose(); //Dunno if this is actually necessary?
}
worn stag
#

i think its good now

#

thanks

#

btw it will erase nativelist every frame?

#

why it doesnt work if i put it in OnCreate()

#

cant get it

#

oh its working nowπŸ˜…

dull copper
#

2019.2.0b6 is out

#

afaik, it works with the DSP Graph from staging

safe lintel
#

does b6 have the ui change fix thing?

dull copper
#

?

#

if you mean the ugui package thing, I think it was addressed a long time ago?

dull copper
#

https://bintray.com/unity/unity-staging/com.unity.tiny/0.16.0-preview


## [0.16.0] - 2019-06-14
* Several improvements when generating a DOTS C# project solution

### [Samples]
* Fixed Browser Interop sample
* Updated Hello World sample
  
### [Editor]
* Fixed delete shortcuts that were missing in OSX
* Fixed duplicate disabled entity bug
* Creating a new empty child Entity by hierarchy drop-down menu will now properly expand the node 
* Dragging scenes inside the unused portion of the hierarchy will not load it
* Fixed WebAssembly.instantiateStreaming bug on Safari (iOS or desktop)
* Text: Fix issue with text and TMP resources not imported
* TextMesh Pro should be initialized without the user needing to import assets

### [Runtime]
* Adding the AudioSourceStart component will now restart the clip
* Volume field of AudioSource is now a slider```
lyric gust
#

what is project tiny?

#

ok.. read the blog on it, a better question is "what does it have to do with ecs?"

dull copper
#

@lyric gust it's using ECS at it's core

lyric gust
#

hmm.. it seems to have samples in the package manager whereas I can't find any for ecs

dull copper
#

it's also only thing that has full ECS editor mode right now

#

ECS samples are on github

#

check the pinned message here for link

lyric gust
#

the last time I tried that they were all for an outdated version

#

I guess I could look again

dull copper
#

dots samples have almost always been updated for the latest version

#

they literally update the repo within few hours from new entities package release

lyric gust
#

interesting.. when I imported it there was a bunch of errors

minor sapphire
#

what's with all the UI package errors with 1019.2.0b6

minor sapphire
#

giving up on b6

#

oh ffs now the same thing back on b2 lol

dull copper
#

if you mean ugui thing

#

that change has been there since all 2019.2 betas and recent 2019.3 alphas

#

just update your packages

#

@minor sapphire

minor sapphire
#

packages are up to date

#

I think I need to upgrade, close, and reopen

gusty comet
#

Hi guys, do you have some sample of how to create a data cache efficiently, in the RenderMeshSystem V2 they just save the chunk position that was culled, but in a case where I just want all the data of the EntityQuery but I know they won't move a lot, I wanted to cache the data as the address of the chunks. Or maybe it's completely meaningless because Array from the EntityQuery are kept until there is some changes?

minor sapphire
#

yep that worked, update, close, restart

dull copper
#

We are planning to have a 3rd drop around mid-august.

minor sapphire
#

DSPGraph is a fancy way of saying "Audio System" yeah? lol

dull copper
minor sapphire
#

I think I watched this a while back

dull copper
#

you can have graphs that don't come with visual node tooling

#

but DSP Graph has at least some visual preview ability if I remember right

#

I saw some nightmarish graphs from megacity πŸ˜„

minor sapphire
#

lol

#

As long as I can have audiosources at the scale we have come to expect from dots...

#

I hate seeing people's profiler screenshots when they have like 15 workers lol, so jealous

dull copper
#

heh, majority of the gamers will not have 8 core tho

coarse turtle
#

so true lol

#

2 - 4 cores sounds like a logical # for most gamers to have πŸ€”

neat pawn
#

is there release notes for 2019.2.0b6?

tawdry tree
#

I'd assume 4 or 6 when it comes to more 'core' gamers (heh), the kind that at least have a beefier laptop or maybe a budget desktop computer. It's by no means a guarantee, but most of newer machines probably have hyperthreading (or whatever the term for having two 'virtual cores' per physical core is), too.
Depends on your target audience, really.

wooden pivot
#

@tawdry tree heh, currently os devs start to disable hyperthreading

#

cause of security risks it adds

tawdry tree
#

I didn't know that, but I also never saw it as particularly useful, since with 4+ cores you already have more available cores than most games effectively use.

dull copper
#

HT is great when you do bigger builds

ember moth
#

can someone tell me what has changed between .31 and .33 for singletons? In .31 it was enough to have the struct with singleton datacomponent added to the entity (used with ConvertToEntity) and use

this.SetSingleton(new SingletonStruct
            {
                Data = data
            });

inside the system which is filling that singleton, but in .33 it broke.

blazing mural
#

Is it possible to use MaterialPropertyBlocks with ECS currently? I was under the impression that it wasn't but it's been a while. I suppose it doesn't work with RenderMesh component but it would work using Graphics.DrawMeshInstanced where a system builds a material property block per entity?

urban rivet
#

hybrid renderer?

#

there was some talk about mpb being wip but part of the plan

#

a while ago

#

(I expect it to be working by now if using hybrid renderer, but would not be surprised if it did not yet)

zenith wyvern
#

As far as I know you still can't do per instance data using the provided hybrid renderer. You can of course do your own rendering with DrawMesh and do whatever you want, including per instance data

#

You still can't pass nativearrays to any of the DrawMesh-es though so it involves copying a lot of data around to make it work

blazing mural
#

I was just taking a look at someone's sprite renderer project on the forums and was confused as to how they instanced it. I appreciate the info! @urban rivet @zenith wyvern thanks!

I'll have to consider how to handle the draw mesh calls then...

dull copper
solid wasp
#

Hi In the last couple of days I started working with multi-threading using the System.threading namespace.

#

So I started wondering if it was still worth using it after the release of the job system and the entity-component-system.

#

In any case could you tell me the differences between the job system and the classic threading system?

tawdry tree
#

As with oh so many things, the answers it probably 'it depends'
But using just one method will simplify things and means you don't need the reference to System.Threading.

#

The job system is specifically made for Unity, for games, and has a lot (a lot) of safety checks built in to make it really hard to mess up, and to work well in a game engine's update loop.*
*runs every update (or at least started from update), as opposed to 'from we start it until it's done'. The nongame version is often faster overall (total average work done per time), but could lead to stuttering if not handled right.

zenith wyvern
#

The job system is nice since it handles dependencies and some busywork for you. If you are 100% confident in your ability to write threaded code without any race conditions then doing it yourself should be faster.

dull copper
#

2019.3.0a6 is out, just saying DSP Graph will work with it

#

(the package)

trail burrow
#

Think I finally finished up all my unsafe collections

#

array, list, ringbuffer, queue, stack, set, dictionary, bitset, heap and three concurrent specialized ones (mpsc queue, spsc queue and spsc memory pool)

vagrant surge
#

@trail burrow you making data structures for the job system/burst?

dull copper
#

knowing how hardcore fholm is about everything, this doesn't surprise me in the slightest

vagrant surge
#

its a job highly needed

#

data structures are super important to have. And the more, the better

#

as if you have more you can select the best for your needs

#

i miss a dense-map or similar type of thing on unreal code, end up allways implementing my own

#

and a few others

trail burrow
#

@vagrant surge yes

#

They are all burst and job compatible, and can be put inside components on entities

#

@dull copper lol

vagrant surge
#

thats really , really nice

trail burrow
#

Still have a few more specialized collections I want to implement

#

Like sorted dictionary

#

Maybe a BVH

vagrant surge
#

what about a sparse-set/flat-set/indirect

#

where you have a hash set as usual, but the actual data is stored in a contiguous array

#

and the hashed thing is the index to the dense array

#

so when iterating you can iterate the dense

trail burrow
#

The hashset is implemented like that

vagrant surge
#

nice

#

so you can iterate the hash set as a fully dense array?

trail burrow
#

Yes, you can iterate through it in a linear array

vagrant surge
#

great

trail burrow
#

My dictionary is faster than the standard .net one by about 33% and than NativeHashMap<T> by about 4x

vagrant surge
#

how is the native hash map implemented?

trail burrow
#

I have no clue, I did a standard hash map and optimized the hell out of it

#

Theirs have concurrency support of course

vagrant surge
#

then it matches with the 4x

#

to have concurrency i think you need to basically make it like a lockfree linked list

#

if your hashmap is openadressing, the x4 makes complete sense. Thats a similar delta to what you can see from c++ unordered_map to one of the abseil hashmaps

trail burrow
#

But you can't put theirs in a component so

vagrant surge
#

how do you deal with the dynamic memory?

trail burrow
#

It's all using native alloc

dull copper
#

you can't reuse the bvh from Unity Physics?

#

tbh, I've not even looked at it's code

#

but people claim it's quite fast now

trail burrow
#

@dull copper no, look at that license and then I won't dare to look in their code lol

dull copper
#

huh?

#

isn't that like standard unity companion license?

trail burrow
#

Yeah have you actually read it? :p

dull copper
#

yes

trail burrow
#

So then you know why I can't look at it and port it to something that can run outside of unity also

dull copper
#

but if you can't accept it, you can't use about any of the new packages

#

ah, you can't reuse it elsewhere, no

#

that's not usually an issue for a Unity user

trail burrow
#

Oh I can use it, I can't just port it to some elsewhere

dull copper
#

but I can see your point

#

especially if you want to run custom backends without unity parts in them

trail burrow
#

Ye

dull copper
#

can you easily port these data structures tho?

#

you'd think your implementation is super specific to this use case

trail burrow
#

The ones I made now?

dull copper
#

yeah

#

if you made them with Bursts terms

trail burrow
#

Yes they're not tied to unity at all

#

All the unity alloc is isolated in one file that can be switched to pinvoke

dull copper
#

ah, that's nice

trail burrow
#

Nothing else touches unitys APIs

vagrant surge
#

great stuff there

trail burrow
#

also implementing a few specialized ones like UnsafeHashMap_4ByteKey and UnsafeHashMap_8ByteKey

#

names of them... is a work in progress lol

#

πŸ˜„

vagrant surge
#

tends to happen lmao

#

how do you deal with destruction, btw?

#

do unity ecs components actualyl call destructors? so you can clean up the resource properly

trail burrow
#

@vagrant surge they are all unsafe, backed by native memory, cleaning them up is the users responsibility

vagrant surge
#

oh

#

ez leaks then

trail burrow
#

yes if you dont know what you are doing πŸ˜›

vagrant surge
#

but useful anyway

trail burrow
#

and even if you do, at times πŸ˜ƒ

vagrant surge
#

im just used to C++ where my containers get automatically destroyed

trail burrow
#
    UnsafeHashMap* map = UnsafeHashMap.Allocate<int, int>(BENCH_COUNT, true);

    for (var i = 0; i < BENCH_COUNT; ++i) {
      UnsafeHashMap.Add(map, i, i);
    }
#

basic usage of the map for example

#

just from my bench test, so nothing fancy

#

they are very C-like, so dont expect any fancy .NET stuff, you can blow your foot off easily

vagrant surge
#

i see. So the maps themselves are heap allocated. Its like in C++ you had a pointer to a std::vector

trail burrow
vagrant surge
#

i can see a lot of use for them. Specially when used with singleton or chunk components

trail burrow
#

most of them can be allocated in two modes, either dynamic or fixed size

#

some can only be allocated in fixed size mode, i.e. array... or some can only be done in dynamic mode like the MPSC queue

#

they all make strict use of data-alignment and cache line sizes where needed for optimal performance

vagrant surge
#

unity ECS inside unity ECS when

#

could stuff like cachesize be automatic?

#

i think you could query the cache sizes dynamically with some instruction

trail burrow
#

@vagrant surge no it cant, there's a global constant used for it

#

it's set to 64 bytes by default, but you can of have a flag to compile it differently for different archs

#

i also allow you to do some more nasty things, like get the pointer to a value inside of a hashmap for example, so you can both read and modify the value with only one lookup in the hashmap

#
    public static bool TryGetValuePtr<K, V>(UnsafeHashMap* map, K key, out V* val)
      where K : unmanaged, IEquatable<K>
      where V : unmanaged {

      var entry = FindEntry(map, key, false);
      if (entry != null) {
        val = (V*)GetValue(map, entry);
        return true;
      }

      val = null;
      return false;
    }
vagrant surge
#

lmao great stuff

trail burrow
#

these are mostly written for my own personal use, but I will dump them on a github under MIT once i've tidied the last pieces of up

#

it also lets you re-interpret the collections

#

like you can create a UnsafeStack<int> and use it as a UnsafeStack<float>

#

or UnsafeHashMap.Allocate<int, short> and get values from it with UnsafeHashMap.TryGetValue<float, ushort> or we

#

as long as the type sizes line up, it doesnt care

mint iron
trail burrow
#

@mint iron there is no way to burst compile anything but jobs atm

#

there supposedly is a generic 'burstcompile' for static methods/delegates comming

#

but it's not available yet afaik

trail burrow
#

hmm i wonder if stackalloc works with burst

#

will have to try that out today

dull copper
#

afaik you can hack current setup to run burst outside jobs but it's definitely not supported by Unity

#

and yeah, they've mentioned few times they'd want to ultimately support something like that officially but it doesn't seem to be high on their priorities atm

#

realistically thinking, it has to happen at some point because there are still plenty of code that would benefit from burst which you can't practically jobify

mint iron
#

yeah you can put [BurstCompile] on static methods, and it will show up in the burst inspector, but i'm not yet sure its actually running the burst version of the method in burst when you call the method. I'm not sure how to tell aside from try to make something slow and see if there's any speed difference with and without the attribute.

#

i was able to get a job scheduled from within a burst function heh

minor sapphire
#

anyone had an error like this when building? :

ArgumentException: The Assembly nunit.framework is referenced by Unity.PerformanceTesting ('Library/ScriptAssemblies/Unity.PerformanceTesting.dll'). But the dll is not allowed to be included or could not be found.
amber flicker
#

Looks asmdef related maybe? Trying to combine the performance testing and ECS?

minor sapphire
#

what do you mean by combine?

#

put them in the same folder / asemdef?

amber flicker
#

I just meant are you trying to run performance test on ecs content? (given this is in the ecs channel?)

minor sapphire
#

nah, I'm just trying to build my ecs project

#

perhaps this is completely unrelated to ecs in the first place? hmm

dull copper
#

@minor sapphire yes

#

use older testing packages

#

I've only seen that if I've manually updated the testing packages to newest

#

there's issue on some of the new ones

#

@minor sapphire json "com.unity.test-framework": "1.0.13", "com.unity.test-framework.performance": "1.2.0-preview",

#

those work for me

#

you may get away with newer test-framework, can't remember why I rolled both back

minor sapphire
#

oh thanks! I'll give it a try

#

aw it didn't help

dull copper
#

really?

#

you restarted the editor as well?

minor sapphire
#

I got it wrong the first time, so I'll try again to make sure

dull copper
#

I also have json "com.unity.ext.nunit": "1.0.0", on my manifest

#

but I think that's there by default for all now

minor sapphire
#

oh hey that is not in my manifest!

dull copper
#

it's probably not on the older editor versions

minor sapphire
#

oh wait

#

it is

dull copper
#

I also only have Entities, Hybrid Renderer and Unity Physics packages here from DOTS stuff

#

so if you've manually updated to never collections, mathematics etc, that might be a difference on our setup too

#

I just take those as dependencies automatically

#

oh, I have Burst here manually too, but that's because I had to do one line edit to Burst 1.0.4 for latest 2019.3 alpha

#

there was small api change that's not on burst package yet

minor sapphire
#

damn restart didn't work hmm

#

I'll have to look more tomorrow

dull copper
#

check that you don't have newer other packages I listed

#

but yeah, it's probably rooted on the actual perf testing framework thing itself

#

all I know is that I got rid of that error by rolling those two packages back

minor sapphire
#

interesting

#

I'll have a look through source control at previous versions of the manifest to see what's going on

dull copper
#

I'd test which one it is on my end but I've updated HDRP from master recently so this would build the project 1-2 hours πŸ˜„

#

well, it might be faster since not everything is new on it

minor sapphire
#

I'll check tomorrow, 1:30am now haha. Thanks for the info.

dull copper
#

gl

#

talking of burst, they have new version coming up πŸ˜ƒ

vagrant surge
#

being able to burst-compile static functions would make so much sense, and be so damn useful

#

for everyone

mint iron
#

i think I've got it working now in a reasonable form, but the catch is its using the runtime compilation, because its the only way so far to get the function pointer. If there were a way to figure out the location of the precompiled version we could wire it up.

#

I can't find the burst dll anywhere, the configs say it should be named lib_burst_generated. Its possible they're doing a dynamic assembly for the editor; like they seem to be for the Burst test cases.

dull copper
#
## [1.1.0-preview.2] - 2019-06-20

- Fix issue where uninitialized values would be loaded instead for native containers containing big structs
- Fix issue where noalias analysis would fail for native containers containing big structs
- Fix issue when calling "internal" methods that take bool parameters
- Add support for `MethodImplOptions.AggressiveInlining` to force inlining
- Fix issue in ABITransform that would cause compilation errors with certain explicit struct layouts
- Disable debug information generation for PS4 due to IR compatability issue with latest SDK
- Implemented an assembly level cache for JIT compilation to improve iteration times in the Editor
- Implement a hard cap on the length of symbols to avoid problems for platforms that ingest IR for AOT
- Add support for `FunctionPointer<T>` usable from Burst Jobs via `BurstCompiler.CompileFunctionPointer<T>`
- Add `BurstCompiler.Options` to allow to control/enable/disable burst jobs compilation/run at runtime.
- Add `BurstRuntime.GetHashCode32<T>` and `GetHashCode64<T>` to allow to generate a hash code for a specified time from a burst jobs
#

this changelog is bit wonky tho, it doesn't contain 1.0.1 - 1.0.4 changes

#

so, they probably missed the notes from those due to some internal branching

trail burrow
#

@dull copper is this burts? ecs? jobs?

#

- Add support for MethodImplOptions.AggressiveInlining to force inlining sexxxxxxy

dull copper
#

new burst package I linked above πŸ˜ƒ

trail burrow
#

yes burst, read the whole changelog now

#

nice with aggressive in lining support

dull copper
#

oh wait, it's on regular registry too now

#

should be available to all

trail burrow
#

@dull copper do you know if you can stackalloc in burst?

mint iron
#

you can

untold night
#

Function pointers? Yes please!

vagrant surge
#

interesting, i thought that burst already inlined the hell out of almost everything

onyx swan
#

Any reccomendations on good places to start with ECS? About to start a new project that I think would be well suited, and would love to use it as a platform to learn.

mint iron
#

(burst) "error: External and internal calls are not allowed inside static constructors" that's new... 😦 there goes the fun.

lyric gust
#

ohh.. finally we get agressive inlining?

#

I've been asking about that for a year

#

@onyx swan check out the pinned messages on this channel

clear stream
#

If i have a dataset that looks like this as a ridiculously large matrix, is ECS / DOTS capable of showing a couple million points simultaneously by going through each row of my matrix at each frame? for example point #1 has an x y and z value prescribed in each row, so at each frame it'd plot position xyz <- mymatrix[time.frameCount, 1:3]. thanks!

#

I want to get an idea of what scale it'll break at

lyric gust
#

you would want to use structs rather than a matrix

#

ECS will then move your data elements into a good order

clear stream
#

so each point would have a structure with an x float[], y float[] and z float[]?

#

@lyric gust

minor sapphire
#

@dull copper , I used "com.unity.test-framework.performance": "1.0.9-preview",. I noticed that's what the dependency for entities was

#

now it works

dull copper
#

huh, that's weird

#

because when I had that, I specifically reset the values to what the other packages had on dependencies

#

but yeah, you are right, it has 1.0.9 πŸ˜ƒ

#

maybe this will fail if I build it now πŸ˜„

#

but yeah, default dependencies worked for me back then

minor sapphire
#

oh man that main thread utilisation issue from a last week has found some kind of resolution!
https://forum.unity.com/threads/ijobparallelfor-jobs-tend-to-not-use-the-main-thread.682078/#post-4671458

The fix/improvement is targeted for 2019.3, and should see main thread help more when waiting for job completion!

onyx swan
#

Ty @lyric gust

dull copper
#

@minor sapphire I lol'd at the start of the response

#

"this isn't a bug in the code" "but code didn't do what it was supposed to"

#

what's important is that it's getting fixed

#

appreciate the persistence of you guys on this πŸ˜ƒ

minor sapphire
#

lol yeah I reckon. working as intended, but intention is not ideal so let's make it better? πŸ˜„

dull copper
#

I'd still classify that as a bug, but still, at least it's getting fixed πŸ˜ƒ

#

most of the issues are like that, oversight in the actual usage scenarios

#

of course there are actual programming errors too

#

but I get probably more the latter

lyric gust
#

@clear stream You can't use arrays in ECS. The most efficient way would be to use one job that acts on a single x, y, and z. That job can run N number of times in a parallel manner using IJobParellelFor

tawdry tree
#

Wasn't there an attribute to stop systems from being created by default?

stuck saffron
#

Isn't it [DisableAutoCreation]

clear stream
#

@lyric gust so each job is for one point, and has a huge list of Vector3?

tawdry tree
#

@stuck saffron That was it, thanks!

#

@clear stream In this case you run the IJobParallelFor X*Y*Z times, once for each point, so it's the same job, just ran a lot of times. IIRC the .Schedule function for IJobParallelFor goes something like (totalIterations, iterationsPerRound, Allocator)

timber ginkgo
#

is there any way I can use a rotational spring force and slerp drive forces on the same configurable joint?

#

I want to simulate opposing muscles, but I don't want to create another configurable joint in the same position todo it

#

the configurable joint wont seem to allow it

timber ginkgo
#

I got the results I wanted by using a configurable joint for the flexor muscle, and a hinge joint w/ spring for the hydraulics

worldly gull
#

Hi all, I am very new to unity. Currently I am making a mobile game. My prime concern is performance efficiency / optimization of the game on various mobile devices. Since using prefabs are way more easy than just importing the asset as game object, is there any problem in importing all-most all possible assets as Prefabs? Will it lead to performance issue or large file size?

timber ginkgo
#

using prefabs is generally for the best

#

one tip for performance is to reuse assets

#

so like, instead of deleting the object when the enemy dies

#

just reset it to a default state and move it out of the way/hide/deactivate it

#

there is this garbage colelctor script, and anything you delete will add to its work

#

basically (i think) the game needs to check and see what memory space has become freed up as the result of object deletions

#

so re-use as much as possible

worldly gull
#

@timber ginkgo thanks πŸ™‚

next kiln
#

Jobs/ECS: Is there any way to make a ParallelFor job use .Add on a NativeList in parallel jobs? There's no need to read or write other than to add an element to the list across the jobs.

tawdry tree
#

@worldly gull The technique Chriscrass mentioned is called 'object pooling' if you need/want to look it up you should find plenty of useful results (maybe add 'unity' to the search terms, too'

#

@next kiln I believe the correct way is to use yourList[jobIndex] = (insert value here). That should work, at the very least. Of course, if the job isn't guaranteed to set the value you will end up with empty indices, but you'll have to consider whether that's a problem depending on your circumstance.

timber ginkgo
#

So I'm trying to figure out why my Slerp drive loses all power in the Y axis when it is rotated 90 degrees in the X axis (1 in radians(

#

any thoughts?

#

so it doesnt lose total power, but it behave very peculiarly

#

im thinking that when it is raised 90 degrees, what was once the y axis then becomes the Z axis, so none of the force is transferred (the z axis is locked)

#

any solutions?

#

yea looks like that's what's happening

#

same thing happens with X and YZ drive mode

#

And I found the fix

#

Apparently having a non zero "limited" range of motion in the Z axis (opposed to "locked") solves the issue

#

there's also some funkiness where switching back and forth between Slerp and X&YZ drives saves the current drive settings and applies them ontop of the drive you have switched to

#

although that is probably an artifact of editing a live environment

indigo orchid
#

Trying to find a good solution for working with per instance material properties (via MaterialPropertyBlock)
I found this thread: https://forum.unity.com/threads/materialpropertyblock-support-in-meshinstancerenderersystem.562369/#post-3773455
and this code: https://github.com/tertle/com.bovinelabs.rendering

I tried converting it to current apis and I'm not getting any actual errors and it kinda works except it seems to be using the same property to draw all of them instead of the specific property for each entity (so they will all draw the same colour even if I set each instance to a different random colour).

Does anyone have and experience/advice/up to date working code for doing something like this?

worldly gull
#

Hi all, Currently I am making a mobile game. My prime concern is performance efficiency / optimization of the game. When enemy gets destroyed there should be a particle explosion. Which will be better to use, a png sequence animation or particle effects? If am using particle effects will it cause any recognizable performance issue.

minor sapphire
#

might depend on the complexity of the effect? but sprite sheet animation will likely be faster, particles themselves are batched sprites in effect anyway. but.. has this got anything to do with ECS? should this be in general code?

worldly gull
#

@minor sapphire in general code

minor sapphire
indigo orchid
#

I maybe solved the problem. I had to use a different mesh for each object, if they are all using the same mesh it won't work. Shouldn't it be the exact opposite?

#

Completely breaks batches though of course so hmm

manic laurel
#

How would I go about iterating over all the entities with the same shared component separately (or just dealing with them all in a separate manner)?
So say I have 10 entities with SharedComponent{Value = 1} and 10 with SharedComponent{Value=2}
I want to handle those separately. But I also want to grab their unique Translation component.
Preferably like to do this in a job compatible manner. I apologise if this is simple but I can't seem to find the information I need to do it.

tawdry tree
#

I think there's an attribute tag, RequireSharedcomponent(typeof(type)) or something similar to do it, but unfortunately I don't remember the specific name (that you put on jobs)

manic laurel
#

Thanks for the tip I will look into. Do you know if that will do the per unique variant iteration?

tawdry tree
#

It's just a filter, so it will iterate each entity, not each of the sharedcomponents

manic laurel
#

I think maybe IJobChunk is what I want and is is correct that I can assume if one entity in a chunk has a certain version of the shared component then all others in the same chunk will as well?

tawdry tree
#

I remember there was some talk about a method to specifically update an entire chunk, but don't remember any specifics. I do know that if you changed it the way you would a normal component, you'd only affect that entity.

onyx swan
#

Is there a way to check the amount of active entities?

#

im spawning a bunch of entities every so often, and would want to make sure i dont go over a certain amount

tawdry tree
#

Hmm, you can get an estimate of the amount of entities in an entity query, I think

#

Obviously, your code would be really brittle if you just checked for total entities that exist, so you'd want to filter it somehow.

onyx swan
#

Yea, i have the specific entities that i want to check for, just didnt know how to see how many active, short of doing something like a count++ in a foreach which seemed like a terrible way to do it

tawdry tree
#

Well, a normal entity iteration is how you do most stuff in ECS, so if you run the check on demand or infrequently (once per second?) you should have no issues. The specific implementation matters, of course.

#

Quick google search points to entity queries. They can also be prepared ahead of time.
https://forum.unity.com/threads/get-entity-count-of-a-foreach-before-going-through-the-foreach.674866/#post-4517983

//In a component system
EntityQuery query = GetEntityQuery(
            ComponentType.ReadOnly<CropTileQuerry>()
);
 
int count = query.CalculateLength();
onyx swan
#

Thanks a bunch!

sonic oyster
#

is this normal?

#

if (Native_blocks2.IsCreated) Native_blocks2.Dispose();

InvalidOperationException: The NativeArray has been deallocated, it is not allowed to access it

tawdry tree
#

Shouldn't it be something like this?

if (Native_blocks2.IsCreated && !Native_blocks2.IsDisposed) 
  Native_blocks2.Dispose();
#

Actually, it might be that Native_blocks2 is null when you do that check, have you tried looking at it with the debugger or logged it?

safe lintel
#

i dont think can be null if its IsCreated, but you definitely have to make sure its not already disposed to dispose it

sonic oyster
#

another question

#

can i somehow make nested nativelist?

#

1D with 2D indexing calculations won't do

#

because: 1. it's for submesh triangles, so the size will differ, 2. creating two NativeLists, one for indexing where a submesh starts and second to hold tris won't do, since my code analyzes the chunk per XYZ, not pet blocktype

#

(voxels)

#

trying everything :v

onyx swan
#

Spent this morning experimenting with ECS for the first time and really enjoyed it.

Made a simple find and move to target system, and was able to have thousands of entitys and hundreds of FPS, which was insane.

My question is, can this be utilized with other unity behavior?

I'd like to make AI thats more fully featured (i.e. animations, different attacks, states) is ECS a viable way to do this? And if so, are there any good resources for it?

lyric gust
#

I hope so Slim. I'm working on an asset that would do that

#

it's still weeks away from release

onyx swan
#

Very cool! i'll keep my eyes peeled for it. Gonna be experimenting with colliders and a hybrid approach until then

mint iron
#

@sonic oyster you can't do nested nativelist or nativearray because the dispose sentinel inside is a class. You can copy the structures and strip out all the dispose sentinel code, but then you will lose that safety mechanism. There are a few alternatives floating around. In the physics package for example they have to deal with similar issues as you for storing geometry so thats a good place to start looking through the code. They have a 'NativeBlob', and there is also 'UnsafeList' in collections package.

tawdry tree
#

@onyx swan, for the moment a lot of features are not ECS ready, so for now you'll probably have to go hybrid, but we're steadily getting there!
Though, if you're making something 2D, you can use Tiny Mode/Project Tiny to get a proper ECS editor and more stuff that works. It locks you to pure ECS, though it's up to you whether that's a pro or con. Tiny mode recently switched from TypeScript to C#, so it's pretty early, but I suggest you give it a ride if you liked the ECS method.

golden heron
#

So a couple of questions, for player controllers, should i bridge the gap via hybrid or should i check for inputs in the update part of a system maybe? Also, is it possible or effective to add more than one component data of the same type to an entity? Specifically, i have a mesh i want to combine, but i want it to keep the original component meshes primitive colliders in the form of ecs compatible aabb boxes of my own implementation. Could this be effectively done by adding multiple aabb components?

tawdry tree
#

Due to how ECS works, I don't think you can have multiple components of the same type
EDIT: Something like this is how I'd do input (can handle singleplayer or local multiplayer, could be jobified for a server-authorative multiplayer game):

class PlayerInputSystem {
  void OnUpdate(){
    entities.forEach<PlayerTagComponent, MoveForwardComponent>(
      //get the correct input and set speed in MoveForwardComponent
    );
    //etc.
  }
}
vagrant surge
#

@tawdry tree using job system for a PlayerInputSystem is completely overkill

#

leave the job system for when you are doing stuff on tons of entities at once. Player input is likely only one

#

unless you want player system to overlap with more stuff of course

tawdry tree
#

Oh yeah, I'm just too used to thinking ECS-> jobs, but in this case you usually have a max of, what, four players, so not running the code in a job makes more sense. Well, I'd still make methods for them, but that's because I like my update methods to be fairly small and just call stuff with good names

#

Revised previous comments to better reflect that

vagrant surge
#

i wonder whats the exact overhead of a job

#

at what point does it become worth it to put something in a job

tawdry tree
#

Well, non-job code runs synchronously on the main thread, meaning it's basically incompatible with any other non-job code

#

So any time making, scheduling, and syncing the job takes less work than the code itself you want jobs

indigo orchid
#

How would one make it so that a [RuntimeInitialiseOnLoad] is called before a systems OnCreate method? Trying to setup my static classes. The setup does require the entity manager if that makes it impossible (creating a static ArchetypeManager class to store all the archetypes I use)

tawdry tree
#

Can you explain the order of actions here?
Like:
On startup: X first Then Y and Z And on update: Use (a) from Y to do W
In short, what needs to happen in what order (particularly on startup/initialization)

indigo orchid
#

On Startup: The ArchetypeManager needs to register the dictionary of Archetypes
Next: The OnCreate for the system needs to run (an entity is created using an archetype)
OnUpdate: Use the created entity to do things.

I may have created a bit of a bad system here truth be told. Just struggling to do it in an ECS manner.

tawdry tree
#

Hmm, doesn't sound quite like the ECS way. The dictionary sounds a lot like a singleton to me, where you don't want it to exists until you need it to exist, and basically cache the results. So you could use that pattern.
ECS also has a singleton helper thingy, which you can read a bit about here:
https://gametorrahod.com/ecs-singleton-data/
Singleton pattern:

public class ClassWithSingleton{
  public static SingletonType Singleton{
    get{
      if(_singleton == null)
        _singleton = GenerateSingletonMethod();
      return _singleton;
    }
  }
  private static SingeletonType _singleton;
}
Game Torrahod

You have these API to work with singleton data but how do they really works?

  • system.GetSingleton
  • system.SetSingleton(T data)
  • entityQuery.GetSingleton
  • entityQuery.SetSingleton(T data)

It's a singleton Entity
In the docs it says "singleton data", but actually you ...

onyx swan
#

For AI i was thinking of using ECS and burst for the simple find and move towards player (still need to work on collisons), is there a way I could use the ECS pattern to instance more in depth AI components (i.e. other monobehaviours and effects) once they got within a certain range of the player?

golden heron
#

Yeah thats pretty much what i did.( @tawdry tree ) the passing through the inputs from the onupdate as floats. I also rigged up a raycasting solution so i can target my entitys by mouse click, and not with unity physics, its my own physics.

#

@onyx swan You'd do well to set up a partitioning system.

onyx swan
#

What do you mean by partitioning?

golden heron
#

Well, think of in a post office, how you split the post into boxes based on intended location, like pigeon holes, except, you do it to the 3d space. The simplest form is to create some kind of array with an entry for each box in your space. You can, if your space is large, or complex, look into nativemultihashmap as this provides a useful way to partition the space and is kind of made for the job.

#

You'd then know each "box" contains objects subject to similar stimuli, similar distances. Depending on your scale, you might do a fairly fine scale and have say gun ranges able to reach up to two boxes, then search the local adjacent boxes... easily done. Or, as i am doing, use it to partition the space quite wide, and then use a second narrower phase inside each box.

#

Mine is for the broad phase detection of my collision system.

#

The nativemultihashmap is a very quick accessing option tho, it wont feel like you are plodding through some slow mess of iterations like your average multidimensional array.

#

Check out the Boids simulation in the ecs samples on github

onyx swan
#

Gotcha, i had something like that in mind. Basically separating which areas react to different behavior. The only real AI i've done in the past was in UE 4, so im still kind of thinking of it like that

#

Thanks for your help!

golden heron
#

No worries!

mystic mountain
#

How do I make my entity have the "WorldToLocal" component?

dull copper
#

add that component to it manually?

mystic mountain
#

So it will update it automagically then^^ I noticed I probably needed the other way around, and that is added by the Convert : )

dull copper
#

I had to manually add that to something some time ago, can't remember why

#

objects started rendering after I added it

#

ah, now I remember, it was that Tertle's proc gen mesh demo for ECS

#

I just upgraded it to latest ECS and needed to add that for it to work

worn stag
#

i'm trying to raycast with new ecs physics

public class RaycastSystem : ComponentSystem
{
    PhysicsWorld physicsWorld;
    EntityManager entityManager;

    RaycastInput rayCastInput;
    RaycastHit raycastHit;

    protected override void OnCreateManager()
    {
        raycastHit = new RaycastHit();
        entityManager = World.Active.EntityManager;
        physicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>().PhysicsWorld;
    }

    protected override void OnUpdate()
    {
        Entities.ForEach((Entity entity, ref Translation trs, ref Rotation rot, ref MainCameraComponent mcC) =>
        {

            Ray ray = Camera.main.ScreenPointToRay(new Vector3(0.5f, 0.5f, 0));

            rayCastInput = new RaycastInput
            {
                Start = ray.origin,
                End = ray.origin + ray.direction * 100,
                Filter = mcC.Value
            };

            bool hasHit = physicsWorld.CastRay(rayCastInput, out raycastHit);
        });
    }
}```
but getting The NativeArray has been deallocated error
what am i doing wrong?
#

error at this line bool hasHit = physicsWorld.CastRay(rayCastInput, out raycastHit);

safe lintel
#

it might be the system dependencies ordering? in a jobcomponentsystem you use the final handle for the physics worlds as a primary dependency for any job you want to query off of the physics, i see they just call complete on the componentsystem version in the physics samples https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/4e5f45339d81699464ff2d6fbd195ae184d45a7c/UnityPhysicsExamples/Assets/Demos/6. Use Cases/RaycastCar/Scripts/VehicleMechanics.cs

#

at the top of OnUpdate() there are some lines you may need to copy for your system

worn stag
#

Thank you very much. I got it working now

indigo orchid
#

Is there a way to dynamically set components.
So for example I have an array of IComponentData, because I don't know the exact type those won't work with SetComponentData

The only viable solution I've found requires implementing a second interface on all compone ts to do the call. This obviously isn't ideal so I was curious if there was a proper way to approach this?

stuck saffron
#

I accomplished that in a not so elegant way.
I use a switch(enum) and then cast to the correct component to add the correct component.

I am also interested in a better way to do it. I plan on changing my implementation when I migrate over to 2019.3 which has Polymorphic Serialization

indigo orchid
#

Oh yeah I considered that but definitely not something I want to do. It would also break my inspector setup.

That might be good though I really wish there was a better built in way.

stuck saffron
#

I just did Custom Property Drawer which helped create the proper component. It was pretty simple as most of my components only needed a float value or int value

#

I think I remember seeing Tiny already has a special inspector for IComponentData

#

May be worth looking into

#

Could lead to ideas

indigo orchid
#

I think for now my solution will be to have an interface:

public interface IComponentDataAssignable : IComponentData
{
    void AssignToEntity(EntityManager em, Entity entity);
}

which I will implement for anything i want to save as:

public void AssignToEntity(EntityManager em, Entity entity)
{
        em.SetComponentData(entity, this);
}

Not ideal but works without too much hassle. No idea if this is going to cause some unseen problems.

frosty siren
#

Noob question: for what purposes we have [WriteOnly]. I understand that [ReadOnly] just saying "Make a copy" and jobs can read same data. But what we achieve when mark struct fields as [WriteOnly]?

tawdry tree
#

In some cases write-only will let you optimize, particularly when doing collections in parallel.
If, for example, you have some kinda list, and you want to be 100% sure you can add to it, but don't care for the order, then you could have an implementation with eventual consistency - if at any point in time you asked what element [x] was, or how many entries it had, it would not know, and could not know, but once everything was done you could check it.
To be fair, I am not 100% sure on this, since it's a while since i read this (was regarding concurrent collections in C#) but I'm sure knowing you will only write lets you optimize something.

lapis yoke
#

I have just created a new project, imported all the DOTS packages, including the preview ones. I have set up a simple scene, with a plane and a cube, converted to entities and using the new Unity Physics system. But I am getting around 80 fps. The same setup with regular gameobjects and the normal unity physics, gives about 500 fps... Any ideas?

dull copper
#

@lapis yoke DOTS Physics is currently tied to the framerate

#

so running at 500fps would require 500 physics simulations

#

where stock physics runs still only 50 Hz regardless how fast you render

#

unless you've changed the defaults

#

and yes, it's a known issue

#

it'll get fixed eventually

lapis yoke
#

Aha, thanks. I thought it was something wrong with the burst compiler or a project setting that was wrong. Then I can start playing with it πŸ˜ƒ

dull copper
#

well, 80fps isn't great figure still

#

but... you should rather measure these costs in milliseconds

#

500fps tells practically nothing

#

well, it tells you aren't really doing any real work yet

#

if you can render actual game at 500fps, you got some really beefy gpu or super simplified scene

lapis yoke
#

Yeah, I know. I'm just used to the physics examples running at several hundred fps, and this very simple test was under 100.

#

But I have not had time to play with it for several months, so a lot has changed with all the packages.

A quick profiling shows that the StepPhysicsWorld is taking ~6 ms, with just the simple cube and plane. I don't know if that's expected and just the Physics waiting for frame sync?

#

But i'll try throwing a few hundred physics entities after it tomorrow and see what that does to the physics steps. Hopefully it will be faster than the collision detection I wrote myself with Entities/Jobs.

lyric gust
#

is there a way in ECS to have one function which chooses whether other functions get run in group or not?

#

I want to run additional processing if the framerate drops below a certain number, so if DeltaTime is large enough I want to run an additional correction function

dull copper
#

put that system in place always and have the deltatime check in it?

#

if it doesn't need to do anything, you just have early out

#

@lyric gust

amber flicker
#

I've no idea if @lyric gust has a similar problem to me but e.g. the second frame in editor always takes 0.333ms so it would be ideal to run a system n additional times if e.g. something should have happened every 0.02ms. One approach I've tried is having a for loop in the update and then use another system to set the iterations (based on the delta time)

crystal zephyr
#

Hey, does anybody used already EntityManager.MoveEntitiesFrom?
I want to move all entities from the current world into another but unity is freezing or going into an endless loop on that line.

crystal zephyr
#

I guess it is because the code runs into this line
throw new ArgumentException("MoveEntitiesFrom is not supported with managed arrays");

crystal zephyr
#

Okay guys, another questions. I creating an nativeArray with Allocator.Persistent. But anyway unity is complaining about memory leak detection because it was not disposed. This should not be raised for the persistant allocator, right?

#

Is Unity doing something magically when I loaded and unloaded scenes in the background? But this should not affect my native stuff.

dull copper
#

@crystal zephyr you sure it's coming from your own code?

#

in past that warning has surfaced x times from Unity's own systems

crystal zephyr
#

Yes, I set the leak detection to full stack trace and it was showing me my line where I create a new native array with Allocator.Persistant. But it might be a bug in the leak detection to not ignoring persistant allocators?

dull copper
#

I've seen people complaining about that too in past (that they get that error with .Persistent

#

but can't remember where people ended with those

amber flicker
#

@crystal zephyr afaik Unity would have you explicitly dispose of the native array, even if persistent

crystal zephyr
#

@amber flicker What do you mean? Sure I have to dispose it somewhen but I wanted to keep it for now. Are the persistent array supposed to get disposed before a scene changes or Resource.UnloadUnusedAssets are called or something like this?

amber flicker
#

so are you getting that when you unload a scene? I think I misunderstood

crystal zephyr
#

Unloading a scene is just what I am doing as well. I will check if I would get the message also without it. But this should be unrelated.

amber flicker
#

also to ask the obvious question - you're aware that once you get that warning the only way to reset it is to restart the editor?

crystal zephyr
#

Yes πŸ˜ƒ

lyric gust
#

@dull copper yeah.. I could always rewrite it to use a while loop for really simple cases, but in more complex cases I need to have different components with a different mix of systems on them. I need to run the "calculate percent done" system then the "calculate position based on percent done" system. Different components would have a different system for calculating percent done. I want to be able to run whichever systems N number of times, where N is calculated based on the value of DeltaTime.

low tangle
#

when you need to adjust timing like that, its best to disable auto update for those systems, and tick them yourself inside of a monobehaviour or componentsystem (which owns the other systems mentioned). in those areas you would do a simple update loop timing with target timing code there. (frame count, or dt based simulation update like physics)

#

@lyric gust

#

the systems updating, when disabled from stock update timing, can be ticked at any point how ever you would like

#

100 updates per frame even.

#

the systems when created manage the dependency generation from their queries, so you are safe to update them

lyric gust
#

A component system which owns other systems.. that sounds interesting

low tangle
#

haven't had a case where I need to update outside of the stock update loop, but it should work just fine

#

usually I just rework my logic and data

#

I mean if you need n number of frames, why not just throw a counter onto the component?

lyric gust
#

Thanks June.. I'm not sure how to actually build such a system, but I'll dig through the documentation with that in mind now

low tangle
#

n entities * 4 bytes per counter (1 if its < 255) is only 4mb per million entities

#

quite literally nothing

lyric gust
#

yeah.. I could see that

#

each system could have it's own threashold and dividing factor, most of them would be above the threashold most frames and thus would do nothing

vagrant surge
#

btw, you can just store the elapsed delta time in a singleton component or the like

#

an just do nothing if its not the time in the system

#

stuff like

low tangle
#

    [AlwaysUpdateSystem]
    class TimingSystem : ComponentSystem
    {
        ChildSystem childSystem;

        protected override void OnCreateManager()
        {
            childSystem = World.GetOrCreateSystem<ChildSystem>();
        }

        protected override void OnUpdate()
        {
            childSystem.Update();
        }
    }

    [DisableAutoCreation]
    class ChildSystem : ComponentSystem
    {
        EntityQuery NewRequests;

        protected override void OnCreateManager()
        {
            NewRequests = GetEntityQuery(
                ComponentType.ReadOnly<AssetRequest>(),
                ComponentType.ReadOnly<LocalAsset>(),
                ComponentType.Exclude<RequestInProgress>()
                );
        }

        protected override void OnUpdate()
        {
            Entities.With(NewRequests).ForEach((Entity e, ref AssetRequest req, ref LocalAsset asset) =>
            {
                Debug.Log("[AssetRequest] " + asset.FileName);
                PostUpdateCommands.AddComponent(e, new RequestInProgress { ID = e.GetHashCode() });
            });
        }
    }
#

key points, [AlwaysUpdateSystem] [DisableAutoCreation]

vagrant surge
#
void Update(){
DeltaComp DeltaTime = GetSingleton<LogicTime>()
if(DeltaTime.elapsed < 0.033){ return}
else{ // do stuff}
}
low tangle
#

and childSystem = World.GetOrCreateSystem<ChildSystem>();
childSystem.Update();

vagrant surge
#

any anyway. Manual system loop is something i recomend in general

low tangle
#

yeah if you want full control go for it

vagrant surge
#

of course ive used ECS more in C++ than unity, so its the default way. but i think having somewhere in your code where you just have the systems one after another is super good to have

low tangle
#

auto created loop is fine for me for now

#

disabling the bootstrap is pretty easy if you want to just take full control of your system update order

lyric gust
#

Thanks a bunch @low tangle

low tangle
#

with the stipulation that you loose all the unity systems being auto created

#

yeah no problem

#

that snippit would compile if you edit my query to your own types, just left it in there because I was working on a asset system and copy pasted it

#

ran it and it works just fine

vagrant surge
#

one of the coolest parts of ECS is just how incredibly simple is to do this kind of "execute once a second" or "work at 30 fps" systems

#

just do it at the system level, grouped if you want

lyric gust
#

interesting

#

ECS based coroutines, anyone?

#

eh.. the burst compiler probably wouldn't handle yield return

dull copper
#

unless... someone made that happen

#

tbh, I have no idea what they are hacking with that πŸ˜„

#

as far as I'm concerned, I'd want to burn coroutines and never see then again πŸ˜ƒ

lyric gust
#

lol

#

why? coroutines are great

dull copper
#

they are overused for what they do

lyric gust
#

they're used often because they are useful often

dull copper
#

I guess my frustration with them comes from seeing people abusing them for things they shouldn't

lyric gust
#

hmm.. you must want to burn lambda expressions to the ground too then

dull copper
#

yes πŸ˜„

#

for a different reason tho

lyric gust
#

and down with linq.. no more fluid architecture...

#

ohh.. injection has gotta go too

#

hell.. delegates in general are often abused

dull copper
#

if you mean the injection Unity's ECS had, then yet, it was awesome they got rid of that

lyric gust
#

kill them

dull copper
#

tbh, I've not seen delegates getting abused much

lyric gust
#

no? you haven't seen people add WAY to many events? an event for everything under the sun

#

public void event Action OnEventThrown()

dull copper
#

just to be clear, I'm mainly now talking about game code and what I've come across, and no I've not really seen people use events much

#

but don't get me started on dozens of singleton managers

lyric gust
#

I have seen it a lot in game code

dull copper
low tangle
#

yeah

vagrant surge
#

Linq is kind of a huge joke

#

the equivalent on C++ (coming C++20, Ranges) is almost zero-overhead

#

a Reverse will just flip the iterators, instead of copying the entire array in reverse like Linq does

lyric gust
#

hmm.. yeah. Several functions for generators... like Reset were never implemented in .net

#

You could do a more efficient reverse if you could reset

#

@dull copper I'm trying to find any kind of operable code in this better coroutines package.. I can't find any

dull copper
#

@lyric gust it's someones hackweek project

#

it just started

visual orbit
#

Hi, quite new to unity.
I have a prefab which has a collider and a script attached to it. The update function just detects the touch. I have multiple objects of the same prefab on the screen. When the user click obj1 and obj2, I want to create a line between obj1 and obj2.
What is the good model to track this kind of sequence?

dull copper
#

it's not meant to be working sample

#

even after hackweek is done, it's going to be just something people quickly hacked together rather than polished feat πŸ˜ƒ

lyric gust
#

Cool, how do you know this @dull copper ?

low tangle
#

@vagrant surge key point here coming C++20 - they are learning and improving! thats a good thing. its not that linq is fast, its that its been nice and functional style! if its still ergonomic and its faster thats a great thing :)

dull copper
#

@lyric gust because Unity's github is now filled with projects and branches that have hackweek, hw19 etc in the name πŸ˜ƒ

lyric gust
#

ohh.. the prefix!

tawdry tree
odd bay
#

Hello, coroutine abuser here

tawdry tree
#

Is this pattern-abusers anonymous now?

visual orbit
#

@tawdry tree Thanks for the pointer. I am aware of line renderer. My question was more around object model and hence I tried this channel. Nonetheless, thanks for the link

tawdry tree
#

ECS (channel name) is a different way to do things from the normal unity way (for the moment, at least), and involves, among other things explicitly downloading a package which is currently in preview. So if you aren't sure if you're using ECS, then you aren't, though if you hadn't heard about it I can see where the confusion came from.
If you're talking about object model as in the logic behind it, then the easiest would be to keep track of the last two objects clicked, no? Perhaps with a selection-box or something like that and a way to deselect.

visual orbit
#

@tawdry tree You are correct. My confusion was about the object hierarchy. I think I was trying to figure out how the statemanager would be incorporated into the system. But I think I found the answer. Again, thanks!!

lyric gust
#

High five @odd bay

frosty siren
#

We can use [InternalBufferCapacity(int)] to set default capacity for all buffers of that type, but what should i do if i want change capacity at runtime?
I see some functions that probably do what i need, but i don't know what they exactly doing. Can someone explain me that?

public void Reserve(int length);
public void ResizeUninitialized(int length);

I guess Reserve(int length) allocate a heap memory block with "length" size.

mystic mountain
#

A bit confused of how I should go about dealing with referenced entities data. My basic system want to copy the position and rotation of another entity. How would I get the referenced entities position and rotation since it doesn't come with the natural iteration?

safe lintel
#

ComponentDataFromEntity

cunning perch
#

It's simple to create a component data for a system to crunch on via a monobehaviour, but how can the monobehaviour get the resulting data back?

low tangle
#

Keep a refrence to the entity manager and query the data

frosty siren
#

I have feeling that a do some things wrong. I update float and i need to do some computations when it comes to 0.5f and 1.0f. So for optimize i use IJobForEach to update float, cause i need to do it every frame, and i use IJobParallelFor to make computations. So to pass entities which i need to compute i use NativeQueue.Concurrent and then iterate over it in IJobParallelFor. To access the data in IJobParallelFor i use ComponentDataFromEntity/BufferFromEntity.

I see 2 problems here:

  1. To access NativeQueue in IJobParallelFor i need to force JobHandle.Complete() right after scheduling IJobForEach
  2. Approach with using CDFE/BFE looks too ugly

Am i use good approach?
I understand that this is very noob question, but with new DOTS documentation i can't find any information.

dull copper
#

from 2019.3.0a7 release notes:

* Graphics: Ability to specify custom Mesh vertex data formats, and set vertex buffer data from NativeArrays. See VertexAttributeFormat, VertexAttributeDescriptor, Mesh.SetVertexBufferParams, Mesh.SetVertexBufferData.
* Graphics: Ability to specify Mesh submesh information directly, and set index buffer data from NativeArrays. See SubMeshDescriptor, Mesh.SetIndexBufferParams, Mesh.SetIndexBufferData.```
tawdry tree
#

That sounds like it's at least partially aimed at helping with the issues you get from trying to use meshes in DOTS

dull copper
#

DOTS or wanting to use burst with jobs for this purpose in general

#

should make proc gen stuff a lot easier to optimize now

vagrant surge
#

thats damn big

#

for people doing mesh edition in DOTS (which fits perfect)

coarse turtle
#

neat πŸ˜ƒ

dull copper
#

ah nice, next dots physics package apparently got terrain collision

fathom trout
#

@frosty siren IParallelForFilter is an option for that kind of situation

untold night
#

Those 2019.3a7 patch notes are tempting me to jump to the alpha instead of 2019.2b7. Does anyone have experience with it as far as stability / package compatibility, or is still "wait on it"?

fathom trout
#

that mesh stuff sounds great πŸ‘

coarse turtle
#

Hmm quick question, since I finally got around to playing with Unity Physics, how do i get to the collision layers again? I remember seeing a + sign πŸ€”

#

whoops nvm, hadn't realised they were assets πŸ˜…

dull copper
#

@untold night it is the usual alpha experience, been on it since first public alpha. Things mostly work, but need to be prepared to use staging packages

#

At a7, it could as well be b1 IMO

untold night
#

cool, I've generally held off on the alphas until later, but "later" tends to vary per release

dull copper
#

For HDRP I stick with github master

#

But that requires often to revert some commits

#

Like right now master from 3-4 commits away from head works as is on a7 but there are 2 commits for api changes after that which hasnt landed on alphas yet

#

@untold night IMO biggest issue on 2019.3 is the new theme atm rather than some random bugs (every unity release has bugs anyway)

#

for example, package manager icons on 2019.3 on the left, and old setup on the right

#

you can immediately tell how easy it'll be to spot the ones with updates

untold night
#

I noticed.

I hope their UX team reconsiders, or at least adds more solid color

dull copper
#

they've also made text smaller in all places but that doesn't mean you fit more

#

you just get more white space

#

and they lack all sensible UI scaling options, they actually have UI scaling but it's fixed step like 100, 125, etc

#

and 25% step it huge

#

they go all the way to 300%

#

but don't have say, 105 or 110 which I'd want to use

untold night
#

honestly, just let us set our own fonts already

dull copper
#

or use our own stylesheet

untold night
#

or change the styling once more things are using UI elements

#

yup

dull copper
#

this all uses UIElements

#

meaning all of the theme is probably in one stylesheet

untold night
#

then we should be able to replace the stylesheets

dull copper
#

I peeked into this

#

and ui elements debugger shows the file even

#

it's just embedded in the unity's editor resources

#

should just have custom theme option so people could put anything there

#

as the system clearly allows it

#

@untold night as for the font, I think Preferences->General has editor font selection

#

but it's only listing 3 options

untold night
#

ah

dull copper
#

Verdana (default), Roboto (UE4 uses this on UI) and Segoe UI

#

the issue with that is the same tho, Verdana is widest font, therefore biggest

#

and if you pick anything else, you'd want that 105-110 scaling which is not an option πŸ˜ƒ

untold night
#

oh well

#

better than nothing, but more annoying

dull copper
#

I'd prefer this one

#

but everything is like microscopic

#

I guess it's good for those people with 27"+ 1080p monitors πŸ˜„

#

I can still use this with my glasses on, but not without and I don't have that bad near sight

#

but I can guarantee that this will cause more eye strain

#

anyway, got bit side tracked from the channel topic again

#

it's just, Unity's UX team triggers me always with their decisions πŸ˜„

#

it's like one step forward and two back

#

to get back on track

#

anyone else noticed Unity leaked latest DOTS packages on the hackweek repo? πŸ˜„

#

like, the wip ones for Entities, Unity Physics etc

#

this is where I saw the terrain collider

#

but apparently, they realized that now as the repo is actually now gone πŸ˜„ (probably moved to private)

#

ah, they hid all the other hackweek repos, they probably didn't mean them to show up in the first place

#

I did manage to clone it before it was gone tho :p

#

was mainly interested on the DOTS gamejams they made, they had two projects there, other was some voxel game for full ECS and other I think was some 2D Tiny game using DOTS mode

coarse turtle
#

There's was a dots networking game they were working on too

#

I only saw the tweets about it tho during hackweek

frosty siren
#

@fathom trout , thank u very much for answer. IJobParallelForFilter is for filter some collection and return NativeList<int> of indexes that matches for your check. In code down bellow i have CompAJob that prepare Queue of entities that matches the check and then pass it to OverHundredJob. To access data in OverHundredJob i use ComponentDataFromEntity. Is it ok to do it like this?

struct CompA : IComponentData { public int value; }
struct CompB : IComponentData { public int value; }

struct CompAJob : IJobForEachWithEntity<CompA> {
    public NativeQueue<Entity>.Concurrent overHundred;

    public void Execute(Entity entity, int index, ref CompA compA) {
        compA.value++;

        if(compA.value > 100)
            overHundred.Enqueue(entity);
    }
}
struct OverHundredJob : IJobParallelFor {
    [ReadOnly] public NativeArray<Entity> overHundred;
    public ComponentDataFromEntity<CompB> compB_CDFE;

    public void Execute(int index) {
        compB_CDFE[overHundred[index]] = new CompB { value = ... };
    }
}
amber flicker
#

yes, imo perfectly fine. The main reason it wouldn't be is that it when you access data this way (i.e. by entity), you lose linear memory access within a job (i.e. you start cache missing). Sometimes that's just what's required. Other times you may be able to change the data layout to be more optimal but that can be very tricky.

frosty siren
#

@amber flicker , in my game i have to update CompA every frame, but CompB should be updated just when CompA comes to 100, so to optimize race conditions i prepare entities for per entity access and schedule job for CompB only when i need, avoiding readwrite access to CompB every frame. I think that manage of race conditions more important then linear memory access in that case, when i have other systems that can access to CompB

amber flicker
#

CompA & CompB are not on the same entity, correct?

frosty siren
#

No, they are on the same entity

#

But in some cases not

low tangle
#

@dull copper is .3 fully using ui elements everywhere? kinda looks like it

#

really wish they would push it out quicker

amber flicker
#

hmm @frosty siren ok.. so.. it sounds a bit confused... the readwrite access & race conditions is what ECS should be taking care of for you - e.g. through use of the JobHandle you return in OnUpdate so I'm not sure I follow your reasoning. Also for the entities that contain both CompA & B, ideally you'd be doing that without a CDFE but that's only if you're goal is max perf

frosty siren
#

@amber flicker ok, here the case: If i will make readwrite access to CompA & CompB every frame in job A, and the second job B would make readwrite access to CompB, then they will never be executed in parallel.
But if i will split first job A to AA & AB, and schedule the AB only when i really need to access compB, then in 99% of frames AA & B jobs can be executed in parallel. Am i misunderstood something?

dull copper
#

@low tangle I think the earlier ones used it for a while too

#

but I haven't checked on those

low tangle
#

oh alright

#

I'm on 1.8 currently and it still mostly looks as it always has

mystic mountain
#

So I'm trying to use the Multiplayer netCode to have multiple worlds, but currently it only registers Systems that are manually marked with Client/ServerSimulationGroup attribute into the worlds. In their sample from what I understand they don't have anything form the scene from the start except the system that conencts the client and server, and doesn't seem to use the Transform system at all, and uses their own rendering. I know I need the TransformSystems in worlds to get physics going, but are the other systems not required to have in Simulation worlds? Is there anywhere I can lookup what these systems do? (image of Astroids demo of default world.

trail burrow
#

@mystic mountain the MP stuff isn't really ready to be used... at all

#

it's very basic atm

#

also depending on what you mean by multiple worlds, it already has support for that? i.e. several client worlds in the same instance for debugging, etc.

mystic mountain
#

@trail burrow Yeah, sure. But I feel like it's better to puzzle it togeather and update frequently than to try go hybrid which has its own cluster of problem and no focus. Looking at their network guide, as my project wont dev out until 20+, it's better to deepdive into this. So yeah, they have multiple worlds, but they don't add default systems to all worlds for some reason, only Begin/EndSimulationEntityCommandBuffer. So I kind of guess if I just add all systems that are in the default world to all simulation worlds it should work fine?

coarse turtle
#

@mystic mountain So i just looked through their networking code a while back

#

From my understanding they created their own world and constructed the systems specifically for client -> ClientWorld and the same for the ServerWorld

mystic mountain
#

Yeah, there is one thing I don't really understand though. They create e.g. a ServerWorld, create a SimulationSystemGroup in that world and adds systems created in that world with the tag. Finally they Sort the update list and add it to the update list of a TickSystemGroup that is created in the default world. Do you have to run your seperate worlds systems through the default world or why would they do this?

coarse turtle
#

Let me install 2019.1.x and take another look at it

coarse turtle
#

So I'm not exactly sure why the TickSimulationSystemGroup would need to update specifically in the Default World, but it there aren't any systems tht are registered to the default world for those groups

mystic mountain
#

So at 345 you see they add the "serverSimulationSystemGroup" to the "TickServerSimulationSystem" of the default world.

coarse turtle
#

Hmm interesting

#

I'll need to play around with it a bit more on the weekends, but it looks like the usage of the Default world is to construct and register systems, if you comment out 345, the server world's systems aren't created πŸ€”

#

this is if you're running on specifically a server via the playmode tools

mystic mountain
#

Hmm, yeah. So how how would you add a system otherwise to the playerLoop that is created from another world?

tawdry tree
#

Systems are specific to the world they're made in

coarse turtle
#

Well for most intensive purposes, what I'm doing is in my tests are:

var prevWorld = World.Active;
World.Active = new World("CustomWorld");
World.Active.CreateSystem(...); // This may not take into account SystemGroups (haven't checked yet)
tawdry tree
#

And if you're following 'true' ECS, they shouldn't care about anything except stuff(ie. entities) in their world

mystic mountain
#

Hmm.. ok. Well then I'm at a loss. The only thing I see is.

            serverSimulationSystemGroup = serverWorld.GetOrCreateSystem<ServerSimulationSystemGroup>();```
So why isn't this creating the systems by itself to the player loop then hmm...
tawdry tree
#

Single responsibility principle?

#

Get-or-create(specific thing) should only ensure that specific thing exists, but not even its dependencies

mystic mountain
#

There's the only place where it's created. So you say if we change that to a "create". It should pop up in the player loop.

#

Hmm. Didn't work for me. Maybe I understood it wrong.

tawdry tree
#

Create (system group)
Create (system1)
create(system2)
etc?

#

I don't know how it works under the hood, and haven't worked much with worlds and system groups, though.

coarse turtle
#

@mystic mountain if you do something like this and wanna register it to the server world you certainly could, but I'm on the same boat as @tawdry tree, I haven't played too much with the worlds/systemgroups API too much.

            serverSimulationSystemGroup.AddSystemToUpdateList(serverWorld.CreateSystem(typeof(FakeSystem)));
frosty siren
#

Is it ok to allocate containers inside jobs and then use them outside?

tawdry tree
#

Can you even do that?

#

That sounds... not quite great

coarse turtle
#

I would also like to say that, the systems in the samples are automatically created via the default world, and in my FakeSystem i disabled AutoCreation @mystic mountain So it's likely that they're simply transferring the systems from one world to another world too

tawdry tree
#

The correct way would be to allocate first, or do a calc for size in job and allocate after, I believe. Depending on needs.

coarse turtle
#

@frosty siren you could do it via unsafe code and storing a pointer...but allocating first is usually the right idea πŸ€”

frosty siren
#

@tawdry tree , @coarse turtle thank u

tawdry tree
#

Find out how much you need, then allocate. Which might mean you want to run a job for that first, but yeah, no allocation in jobs.

frosty siren
#

Yeah, u understand me right)

frosty siren
#

So much noob questions i ask today, i'm sorry.
I'm in case when i have IF at start of my OnUpdate, inside of which i schedule a job, and at the end of OnUpdate i schedule a job too but without IF. It's look like

protected override JobHandle OnUpdate(JobHandle inputDeps) {
    JobHandle resultJobHandle = ???;
    if(...) {
        var jobHandle_A = new SomeJob_A{...}.schedule(inputDeps);
        resultJobHandle = JobHandle.CombineDependencies(resultJobHandle, jobHandle_A);
    }
    var jobHandle_B = new SomeJob_B{...}.schedule(inputDeps);
    resultJobHandle = JobHandle.CombineDependencies(resultJobHandle, jobHandle_B);

    return resultJobHandle;
}
```So i stack at how i should initialize resultHandle
```csharp
var resultHandle = inputDeps;
```or
```csharp
var resultHandle = new JobHandle();
trail burrow
#

@frosty siren you chain all of them with input deps

tawdry tree
#

You should return whatever handle best represents the system, which usually means chaining

trail burrow
#
inputDeps = new Job2().Schedule(inputDeps);
inputDeps = new Job3().Schedule(inputDeps);
return inputDeps;```
#

if you dont know what you are doing

#

that is the safe way

tawdry tree
#

Usually as in, "unless you somehow have a big branching tree", but if you have you should be asking yourself why.

#

But yes, +1 to fholm's more straightforward answer of making a direct chain

frosty siren
#

Ok, i think i got it, thank u all

mystic mountain
#

@coarse turtle What you mentioned was an add to the "serverSimulationSystemGroup" which is added to tickServerSimulationSystemGroup, or did you comment that line out and still made it work?

coarse turtle
#

I did not comment that line out

frosty siren
#

I'm trying to optimize my system work and i can't figure out how i can dispose containers without forcing JobHandle.Complete() (except NativeArray).
As i can understand the only way to prepare array in parallel jobs is to use NativeQueue or NativeMultiHashMap, cause only those containers have .ToConcurrent(). Also after filling NativeQueue i need to transform it to NativeArray to be able to access it in parallel. And in the end i need to somewhere dispose NativeQueue. All of this looks dirty.
I also understand that i can dispose my queues at the start of OnUpdate, but in my case it's impossible.

So what the most clear and best way to schedule disposing of your native containers?

dull copper
#

oh, found this reply from Joe from two months ago: the burst compiler will support cross platform floating point determinism end 2019 / early 2020.

#

I didn't realize they set it that far back

#

it was initially estimated to arrive last winter and then spring 2019

#

4. Is the new DOTS Unity Physics deterministic?
4. It deterministic but not yet cross platform deterministic since burst does not support cross platform float determinism yet.

#

I'd take that reply with a grain of salt

#

how I'd read that is that DOTS physics is deterministic by design but they can't yet guarantee it with Burst

coarse turtle
#

interesting πŸ€”

dull copper
#

also crossplatform can mean many things

#

if they can guarantee Burst is deterministic with the same build regardless of the cpu achitecture, that would be great already but I somehow don't think that's the case

merry oasis
#

i have this system thats creating entities to render stuff with, right now im just storing the result of
PostUpdateCommands.CreateEntity
but this seems to have some problems when i try to actually use that to get, say a RenderMesh so that i can update it

#

from what i understand, PostUpdateCommands returns an Entity with an Index that is negative of the actual value, say -1, then when the command buffer is actually evaluated at the end of the frame, the new entity is actually assigned positive 1

#

so to fix this do i just need to negate the Index that i get from PostUpdateCommands.CreateEntity ?

#

i don't access the new entity until the next frame so im not worried about creating and using it via PostUpdateCommands in the same frame

#

i tried just negating the index and that just throws a ArgumentException: The entity does not exist

upper tiger
#

Hey all,
If i want to run some code before ComponentSystems start, how do I do that?

dull copper
#

this makes me sad

#

Joachim just replied to the DOTS editor thread on the forums: ```Our focus is on making the GameObject -> Entity conversion workflow production ready.

We will do a lot with visualizing converted state, warnings / error overlays in inspector, live conversion, asset database caching, player live connect over the next half year. ```

#

I mean, it's "nice" that you can convert but it feels so dirty and hacky

#

I'd rather have full blown DOTS editor that works

#

I guess the reason for this is that they can't make entities package production ready this year with the full editor, so they need to come up with something else so they can market this at bigger studios etc

upper tiger
#

Why is this
entityManager = World.Active.EntityManager;

causing an object reference not set to instance of object error?

#

only broke when i upgraded my project to latest beta

trail burrow
#

@dull copper seems like such a hack

dull copper
#

it really feels like like something they had to make to reach some target

#

but would have still wished they took different path

#

conversion workflow felt like nice temp workaround to get things done but I'm not really happy about them putting this much focus into it vs the actual dots editor

#

originally it felt like it was fast way to try new things but when it goes to polishing it, it's totally different thing

frosty siren
#

@upper tiger if u talking about running code before specific system, then i think u can use OnCreateManager()
But if u want to run some code before all systems starting then probably you should create World manually

upper tiger
#

I guess I want to create a reference that multiple systems use, such as the terrain. So at the start I find the terrain, get a reference to it and store that in a static variable that is accessible from all systems

#

but it has to happen before those systems load otherwise they will try to run code with a null terrain variable

neon shore
#

Most people will probably go for a hybrid approach because most people just don't understand ECS yet. That's probably why that's their focus.

frosty siren
#

@upper tiger in my project i successfully call Start() on Mono and get all required references before systems run

upper tiger
#

Dont want to use mono

#

pure ECS

frosty siren
#

why not to use mono and then just destroy it after start work?

upper tiger
#

I think I can use
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]

neon shore
#

Have you tried OnCreateManager=

#

?

upper tiger
#

say I have 10 systems, which OnCreateManager runs first

neon shore
#

Not sure, I'd assume they get run in the same order the system updates do.

upper tiger
#

maybe, but i still need to control that

neon shore
#

You can control that order.

dull copper
#

oh I didn't mean hybrid couldn't exist, it has to exist for the time being

#

but if they would have made DOTS editor extension so that it could coexist with the gameobject scene editor, it would make the transition or using both seamless

#

now we just keep getting things that exist only on one side and get full editor open only for one side

#

it's so far from what it could be

#

if they did that, there wouldn't be need for more advanced tools to show the temp phase

#

they could just focus on the real editor and moving the two things between in seamless fashion

#

"We will do a lot with visualizing converted state, warnings / error overlays in inspector" <- stuff like this wouldn't need to happen, we wouldn't need to author entities in gameobject side to immediately convert them over when game starts

#

we could just author hybrid things on gameobject side and entities on DOTS side from the start

low tangle
#

I personally don't even use any of the conversion api

#

my core game is started from a preload static method

#

which creates the entities needed to kick off the rest of the systems

#

hybrid objects are created and managed by systems way later on in the api

lyric gust
#

how do you preload a static method without a game object?

neon shore
#

You can do a Bootstrap class.

#

for example

low tangle
#

yup ^

#
        public static void Initialize()
        {
}```
#

oh right, I do that then augment it with a in scene settings object, holding a bunch of random stuff

#

but thats only for the editor version

#

    internal class SceneStartupSettings : MonoBehaviour
    {
        public enum EditorStartupMode
        {
            None,
            Server,
            Client,
            LocalHost,
            AutoJoin
        }
        public EditorStartupMode EditorMode;
        public string AutoJoinIP;
        public ushort AutoJoinPort;
        public bool NoSteam;
        public bool NoDiscord;
        public bool ForceVR;
        public bool Oculus;
        public bool Vsync;
        public bool LogExtra;
        public bool DisableUI;

        public string User;
        public string Password;
        
        public string WorldGUID;
        public string PlayerGUID;
        public string VersionOverride;
    }
#

but personally I'm thinking about moving to two scriptable objects, one for base game, second one for editor only values (overrides for my api, and disabling things)

#

I already use a settings.ini system I wrote as well. these are mostly for static asset refrences without going to resources.load

#

back in the init method, I store some globals for faster lookup inside of the MyGame.Systems namespace:

//Grab the auto created world
            World world = World.Active;
            ECS.EntityManager = world.EntityManager;
            ECS.DefaultWorld = world;
            ECS.PlatformSwitchingSystem = world.GetOrCreateSystem<PlatformSwitchingSystem>();

            //Create singleton data
            var ent = ECS.EntityManager.CreateEntity();
            ECS.EntityManager.AddComponentData(ent, new RequestSettings { MaxRequestsAlive = 100 });
dull copper
#

new Entities package must be close, we've gotten new version each month this year but this one, so it's probably going to release soon

#

I guess the biggest change will be the option to add/remove components and entities inside ForEach lambda

safe lintel
#

i used to be able to remember from comments what the new package would have but i cant remember whats what for the next one

dull copper
#

well, that was actually from the leaked entities package from one hackweek repo :p

#

they got dots master there

#

the physics package change is bigger as they changed the api a lot

#

I still dont get why they dont keep that repo open for all

safe lintel
#

too many people complaining that stuff isnt working maybe?

dull copper
#

I dunno, SRPs have dev branches on github along with other unity feats

safe lintel
#

i wish they had a community manager for just dots stuff

dull copper
#

or like, roadmap with proper estimates πŸ˜„

safe lintel
#

squeeze some more info out of em πŸ˜ƒ

dull copper
#

like even four quarter estimates

safe lintel
#

lol almost asking too much

dull copper
#

we do know somewhat around that ballpark on when things are going to land

#

but that info is scattered in random places

safe lintel
#

yes that squiggle graph πŸ˜„

dull copper
#

should do some community driven roadmap with ref links to sources πŸ˜„

#

wiki style

safe lintel
#

not a bad idea

minor sapphire
#

also, wasn't the havok physics announcement meant to happen in June? or was it July...?

dull copper
#

I think they only said this summer

minor sapphire
#

oh, I was simply thinking about the announcement itself heh

low tangle
#

hmm

#

missin deadlines I see

dull copper
#

well, one shouldn't put that specific deadlines that far away in the first place, they never stick πŸ˜ƒ

#

I can also see many issues in the plan

safe lintel
#

where was this hackweek repo? 🍴

dull copper
#

basically they want to keep unified API for both new Unity Physics and Havok integration, but Unity Physics package is still very alpha, so it's API will evolve

#

and this means that if they publish Havok integration they need to constantly change that too then

#

it feels like a thing that should have been done only after they figured what all Unity Physics needs

#

@safe lintel it was on the main Unity github, but it's gone already

#

they cleaned most of the hackweek stuff from there at once (probably just set them to private)

safe lintel
#

doh

vagrant surge
#

what about the renderer stuff?

#

from here

#

would def like to know how that works

dull copper
#

I'm super puzzled about the current Unity's rendering plan

#

they are about to get HDRP out of the door

#

but it doesn't utilize any new DOTS perf improvements

#

and it's very likely that at some point DOTS will have a dedicated renderer that is not HDRP

#

but developing new HD renderer for years just to have it being replaced after just few years after release sounds super silly as well

vagrant surge
#

@dull copper the render pipeline can have parts done in DOTS

#

the work on the whole render pipeline stuff isnt the same as DOTS renderer

#

in fact, most of the hardest work is on the shaders and visual effects

#

and those are in glsl/whatevre

dull copper
#

you'd think, yeah

#

in hdrp, they heavily utilize compute shaders

#

but they've actually gone bit back to more traditional shaders on some as just stuffing everything on gpu compute didn't bring the best perf

#

but for example, current DXR's experimental version is heavily CPU bound

#

of course that doesn't reflect how the final version will be, we'll see if it's still cpu heavy on next falls HDRP

vagrant surge
#

unity has a very interesting powerup on the DOTs stuff

#

making it simpler to create highly parallel code is a huge deal

unborn bear
#

I was wondering, is it possible to Blit without freezing the engine ?

gusty comet
#

Hi guys. I'm Trying to call Camera..WorldToViewportPoint() from an ECS job but its saying It can only be called from the main thread. Is there any way around this? Google yields no details how to implement it myself and it's natively implemented so no source.

amber flicker
#

@gusty comet unfortunately this is what's expected with the hybrid workflow (any access to monobehaviours needs to be via main thread). That said, doing it once per frame shouldn't be too bad? Unless you have thousands of cameras πŸ˜„

#

FYI you can call Camera.WorldToViewportPoint() in the system's OnUpdate and pass it to your job

mint iron
#

Hey i was wondering, is the system timing in the entity browser/viewer ui (i forget what its called) taking into account the duration of jobs scheduled or is it purely what happens in the update method.

gusty comet
#

@amber flicker I can't just call it outside, I am doing it in side a job, for each of potentially thousands of components. That's why I asked for how to do it manually.

amber flicker
#

@gusty comet so you do have thousands of cameras?

gusty comet
#

no thousands of units.

amber flicker
#

oh I see

gusty comet
#

you pass a different position to the method for each

amber flicker
#

gotcha

gusty comet
#

so if I knew how to do it myself, I could do it in the job in my loop

amber flicker
gusty comet
#

I am doing this for another dev actually, who insist he must do it this way

#

I'm gonna talk to him again, I had the same thought

amber flicker
#

Cool - understand there are reasons to do things a certain way sometimes but I have a feeling that could get a bit expensive quite quick... good luck!

mystic mountain
#

Is it possible to create an archetype from a prefab?

knotty quail
#

Any of you code/script terrain tools?

frosty siren
#

omg, to dispose NativeArray after job we should use [DeallocateOnJobCompletion], to dispose NativeList we should use NativList.Dispose(JobHandle). Why so chaotically?

flat scroll
#

@knotty quail you got questions?

knotty quail
#

@flat scroll, yeah there is a low poly terrain editor that is depreciated from two years ago, and was hoping someone might be able to fix it and make it compatible with newer version of unity.

tawdry tree
knotty quail
#

I tried there, it moves pretty fast and gets buried so no replies other than a self proclaimed 15 year old that tried for 3 minutes, lol.

#

πŸ˜†

flat scroll
knotty quail
#

Yep, wasn't sure programmers paid attention to that either.

flat scroll
#

mostly me haha

#

from unity at least

#

but there are a few programmers that chat there

knotty quail
#

I am surprised I haven't seen a good solid low poly terrain editor go into the unity store and I have been on and off with unity for years.

#

Does the new terrain system have the ability to toggle flat shading by chance?

#

I don't want to use a custom shader as they can be resource intense at that scale and pop like crazy on LOD's at lower settings. 😦

flat scroll
#

I'll try to answer these back in the terrain channel

knotty quail
#

Thank you

frosty siren
#

I have an error:
The previously scheduled job Utils:QueueToArray1 writes to the NativeArray QueueToArray1.queue. You must call JobHandle.Complete() on the job Utils:QueueToArray`1, before you can write to the NativeArray safely.

Little bit confused, cause field "queue" is not a NativeArray, it's NativeQueue.
And also my second job scheduled with JobHandle of an prev job, so it will start write to queue only when prev is completed. I guess there is some attribute for this kind of problems.

tawdry tree
#

Did you properly queue the jobs?
Meaning something like:

var jobHandle1 = job1.Schedule(inputDeps, eventualOtherArgs);
var jobHandle2 = job2.schedule(jobHandle2, eventualOtherArgs2);
frosty siren
#

yeap. i chained all with inputDeps, so it can't be wrong

tawdry tree
#

Wait, you made ALL of them depend on inputdeps?

frosty siren
#

yes, like

inputDeps = job1.Schedule(inputDeps, eventualOtherArgs);
inputDeps = job2.schedule(inputDeps, eventualOtherArgs2);
tawdry tree
#

Ah, you just override inputdeps, that works. It sounded like maybe you scheduled both jobs after the original inputdeps, which would be a fairly obvious cause for that issue.

frosty siren
#

i have no problem with jobs that access to the same native container except this two. But the difference is this jobs both WRITES to container

hollow sorrel
#

@mystic mountain only just saw your post
not sure if it's the right way but
you can put a ConvertToEntity behaviour on your prefab together with some script that adds the wanted components on conversion and then

Entity sourceEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(myPrefab, World.Active);

then you can use that as archetype to instantiate your entities
however sourceEntity gets instantiated too i think so far as i know you gotta use destroyentity on it when you're done, not sure if that is the intended way to go about it so anyone feel free to correct if there's a better way

mint iron
#

I have a an Entity prefab created with with ConvertGameObjectHierarchy and on the game object to be converted is a monobehavior with IConvertGameObjectToEntity that adds an extra ComponentData to the Entity.

The resulting prefab entity does include the additional component. However when i EntityManager.Instantiate the prefab in a system, it uses the wrong archetype, excluding the extra component. Anyone been through this or found a workaround? I am quite confused.

basically my goal is to use ConvertToEntity but have the resulting Entity include a few extra Components (and not add them manually after instantiate)

gentle osprey
#

Hi everyone, was hoping I could get some input on a somewhat architectural problem where I feel I am digging myself down a hole. Essentially, what I want is to have an entity with a component that contains a complex structure; a collection of bounding box grids (layered according to size, so essentially List<List<AABB>>). However, due to the requirement of primitive and blittable types I haven't really found any good ways to get that into a single component (I have some ideas for bad ways). Anyone have any ideas on how I could do this?
Essentially what I would need would be a way to create a 2D Dynamic Buffer
(Jumping back to monobehavior for this data structure is a valid option and I am currently considering it, just wanted to hear here first)

indigo orchid
gentle osprey
#

I did try using dynamic buffers, however, then I can only get 1 dimension.

indigo orchid
#

You can just index with that in mind

#

Convert the 2D index into a 1D index

gentle osprey
#

I can, but I am already 3D to 1D indexing in there since its a 3D grid, and adding a 4th dimension wasn't really what I was hoping to do.

#

The thing I am sort of thinking back on is whether or not I actually want this thing as component to begin with, or if it should really be a system almost. I mean, I will never have more than 1 of it, and outside of visualization for debugging I am only using it for queries.

indigo orchid
#

I am new to Unity ECS myself but if you only ever have one of it and it is complicated like you say then making it a system may make sense, but can't comment much beyond that without knowing more.

amber flicker
#

@gentle osprey have you considered one entity per AABB? Is the idea that a cell in your 3d grid has multiple AABBs?

west temple
#

Can i use ECS productive?

gentle osprey
#

It's for a streaming system (streaming stuff off of disk). Essentially its just a spatial querying structure (like an Octree almost). I will just be using it to check if a player is within one of the cells then use that information to load in the rest of the world. The voxelgrid has several sub grids (for reasons), which is why I would like a 2D approach, so I have a collection of layers of VoxelGrids.

#

@amber flicker I tried such an approach, the problem is that I need to know what index an AABB is within the grid.

indigo orchid
#

Honestly, I do something similar (though it is 2D) and I use a system to do it

fallen sleet
#

Can you hold your data structure somewhere else, and store an integer index into it inside the component?

amber flicker
#

@gentle osprey Not sure I can be of much use but I wonder if (re?)looking at the boids or even the physics broadphase might be helpful? e.g. the boids hashes the position

stoic monolith
#

Hi all. It's a weird to ask this here but, i'm not doing any ECS and i'm getting this sometimes

To Debug, enable the define: TLA_DEBUG_STACK_LEAK in ThreadsafeLinearAllocator.cpp. This will output the callstacks of the leaked allocations```
in a standalone, master server stuff process in cmd (MSF does use multi thread in this, but still, no ECS). Looks harmless, but when i Ctrl+C, it crashes. This is probably unrelated, but i'm just trying to debug. Why i'm getting JobTempAlloc stuff?
Yes i'm using PostProcessing.
And whats worse is, this only happens sometimes... and when this happens, something else that should happen is not happening
gentle osprey
#

Ah, Discord came back up again, cool. Great idea @fallen sleet, I'm going for that one :) (or at least a variation of it), thank you so much for your help people :)

indigo orchid
#

@stoic monolith
I get that problem too. I think it may be a bug (someone correct me if I am wrong)

stoic monolith
#

But you're doing ECS, right?

indigo orchid
#

Oh yeah, I am. But it doesn't always start happening after chanigng any ecs stuff. Do you know if there is any job usage?

gentle osprey
#

I have had a similar problem actually, was wondering if it was a bug. I had a leak, got that message, fixed the leak, but the message doesn't dissapear until I have restarted unity.

stoic monolith
#

None at all except maybe from PostProcessing.
And this is from a standalone build, so maybe i should try restarting PC?

#

But then again it's set to server build, so it's headless, no graphics. Not sure if it'd stop PostProcessing.

frosty siren
#

How NativeMultiHashMap.GetKeyArray() works?

merry oasis
#

it just does

frosty siren
#

nobody knows?)

low tangle
#

the guys that wrote it probally know

#

kidding, it just returns a native array of the keys? what do you not understand about that

frosty siren
#

I mean how it's generated.

#

the array of keys is not stored in the hashmap, isn't it?

#

I mean hashmap of course contains all keys but with split lists, and i don't know how it's implemented in DOTS (actually i don't know hashmap data structure well), so i worry about perf. But based on your words i think it's just simply connects all keys into array)

low tangle
#

you can check the source of native hash map for yourself

#

@frosty siren

final fox
#

Just a question before freezing πŸ˜ƒ Can I use NativeArrays in ISystemStateComponentData ?

indigo orchid
#

I am getting some reasonably intense jagged edges after rotating a quad mesh with the Rotation and Rotation pivot components. Is there something I should be doing to avoid this?
And if I am trying to rotate around the centre of the quad is the pivot even necessary?

shy garnet
#

Which tutorials to start with ECS do you recommend?

dull copper
#

none

#

they are all outdated

#

@shy garnet

#

but if you start with something, look at least the official manual & docs

#

they are linked in the pinned message in this channel

shy garnet
#

ok, thank you very much, I knew it was difficult and if I tried to search it by myself I was sure it will be outdated xD

fringe sinew
#

I'm a bit confused about Burst and the whole stack

#

Unity Technologies says how awesome ECS and Burst are, how they are more performant than the same code written in C++

#

However, this only applies if all of your code is in ECS, with Job systems and those Jobs compiled with burst.

#

Otherwise, ECS code compiled with IL2CPP is 2-3 times slower and ECS code compiled with Roslyn is further 2 times slower than the IL2CPP build.

#

How can this be considered a nice thing? Burst is not supported on all of the platforms (looking at you, nintendo switch) and it is not supported in non-jobified code.

#

Just imagine: Unity says how good their new DSP Audio System is great and dandy, but all of its speed depends on burst.

#

What's the deal with that?

dull copper
#

@fringe sinew the idea is that you will always use Burst

#

and currently, DOTS is quite barebones, so it's not really good to compare it to existing things directly

#

Unity hasn't said this is thing you should jump into today

#

in fact they've said it will takes years for this to be a thing you should really use

fringe sinew
#

But I'm still quite confused. Burst seems such an afterthought, easily breakable in the process. It all seems like IL2CPP all over again which can't compile half of the time on consoles

dull copper
#

I don't understand this at all tho: Otherwise, ECS code compiled with IL2CPP is 2-3 times slower and ECS code compiled with Roslyn is further 2 times slower than the IL2CPP build.

#

"ECS code compiled with IL2CPP is 2-3 times slower ", slower than what?

#

" and ECS code compiled with Roslyn is further 2 times slower than the IL2CPP build.", wasn't this what you compared the first one against?

#

I totally missed the point here

fringe sinew
#

According to their own blog post and Aras' blog about a C# raytracer, Aras' profilings show that a NET Core version of the code runs 2-3 times slower than the C++ code, IL2CPP code in unity runs comparatively to the NET Core version and the unity Mono compiled code runs 2 times slower than IL2CPP and NET Core code

dull copper
#

Burst is one of the core things on this whole concept, it's what enables a lot of things, it's not just the perf either

#

burst gives them full control over the compiler, they can do determinism, handle precisions etc

#

uh, so you compare c# to c++ now

#

but we don't script in c++ with Unity in the first place

fringe sinew
#

Not me, Unity themselves, in a blogpost about performance

dull copper
#

it's only meant to give people some idea where these are at

#

the results you get vary a lot too depending what you actually do there

fringe sinew
#

When I (and they) talk about C++ and NET, they meant about the code outside the unity, to test later how it compares to Mono and IL2CPP builds in Unity

dull copper
#

2-3x slower doesn't mean anything in DOTS

#

it's like totally irrelevant info

#

you can get 50-400x speedups with ecs + jobs + burst

#

nobody cares if you get 2x slower code if you only use it for C# ECS vs c++ code comparison

fringe sinew
#

I think you miss the point of the blog post I'm talking about.

dull copper
#

as that's not the intended use case

#

I know the blog post, I've read it

#

but you really need Burst for this all to work well, and doing perf comparisons without it is just silly

fringe sinew
#

I understand that we'll need it, but, as I stated before, I'm just confused about such a decision behind burst

#

For example, it's JIT only, compiled at the start or the first schedule. How can that be a good thing?

dull copper
fringe sinew
#

Of course, it's to these blog posts that I'm referring

#

You completely miss my initial question here.

#

I am confused behind the decision of Burst.

dull copper
#

but that's explained on those blog posts?

#

there are some Unite talks too that explain more about the reasoning behind it I suppose

shy garnet
#

C# is for speed at development phase
IL2CPP is to make the active code you got from C# more performant
DOTS is a way to sort data to have an improve of performance over other orientations
All of them are improvements, and all of them will run independently.

dull copper
#

*IL2CPP isn't about perf at all

tawdry tree
#

Isn't IL2CPP more about platforms?

dull copper
#

it just can be faster in some cases

#

yes

shy garnet
#

oops I missed that then xD

#

I thought it will be improved to have better perform through getting the benefits of a CPP compiler

#

I mean yeah about platforms is a need, but about this topic about performance it's involved too

dull copper
#

there were 2 big reasons for IL2CPP originally: to get AOT builds for IOS as apple didn't allow JIT anymore and other was to be able to run emscripten (to convert c++ to js) so they get webgl builds (after chrome banned Unity's webplayer plugin)

#

and after that, it was used on other newer platforms that didn't have support for Mono version they had

#

nowadays Unity has many platform targets that only support IL2CPP as scripting backend

fringe sinew
#

First of all, it is JIT only. Why is that? That can't be a good thing a lot of the times because of code modification. Why isn't it AOT?

Second of all, it compiles directly into native code. Alright, what if I try to run my old game somewhere with a new architecture (a new SSE iteration perhaps)? How will that do? Mono will surely compile fine, IL2CPP and UE4 games will also be probably fine, but what about Burst's JIT?

dull copper
#

what is jit only?

fringe sinew
#

If I am not mistaken, Burst code is compiled at runtime on the target machine.

dull copper
#

When working on your projects in the editor (play mode), burst works in a Just-In-Time (JIT) fashion.
However when you build your project into a Standalone Player, burst will instead compile all the supported code Ahead-Of-Time (AOT).

#

they had some chart about JIT / AOT between all unity things somewhere but not sure where it was

tawdry tree
#

In short: JIT in editor for speed, AOT on build for perf

#

Is what I'm taking from those quotes

dull copper
#

today, Burst also builds for example SSE2 and SSE4 both for windows builds and it picks up the one that your computer supports when you run it

#

I guess it's same with linux and macos

shy garnet
#

TIL about that IL2CPP thanks xD

dull copper
#

and as for new CPU's, you don't have to do anything

#

we already have extensions like AVX, AVX2, AVX512 that are not on all cpu's. of course you'd need dedicated support to enable these but older extensions still work on these cpu's. Practically every PC that can run Unity, supports SSE2, Steam's hw survey says 100%. For SSE4 the figure is ~96% (due to old athlons, phenoms and pentiums lacking support for it). But if new cpu comes along it will definitely support both of these.

#

I've been asking for AVX support on Burst for quite a while but it didn't really make much sense in past when Burst didn't build for multiple extensions yet

vagrant surge
#

@fringe sinew ive made an open source unity-style ECS

#

ive also made a boid flocking system

#

its 10 times slower than unity boids sample

#

and thats running on a custom engine where i use instanced rendering to render the entire scene in 1 drawcall

#

the burst thing is really felt

#

it does generate faster code than C++ in nearly all cases. In fact, if it doesnt, its considered a bug