#Beginner DOTS

1 messages · Page 1 of 1 (latest)

tulip moon
#

Hey, i'm beginning to look into ECS, but having alot of difficulty finding resources.

I'm trying to start basic, such as "create entities that move and add health components". I've added a physics component and I'm trying to make an overlap sphere interact with it.

I can see that the entity has all the components it should need.

The issue is its unclear if gameobjects can communicate with entities.

I want to keep the player a gameobject type, but make all enemies ECS since the plan is for mass spawning and performance on that end.

Though most resources are entity player/projectiles communicating with entitie enemies.

I haven't found a resource where its "overlap sphere accesses health component/spawn damage component to damage enemy"

Can physics overlap even affect the entity? I was reading that may not be possible, and it needs an entirely different setup since subscene and scene are like two planes of reality in a way.

The only thing i can think of is spawning an entity compatable object at the player gameobjects location, but it spawns inside the subscene where the entities can see it and be affected by it. is that the only way to do it?

#

Here's sample code that I went through multiple revisions with (ChatGPT) since i'm trying to do something specific.

#

It seems to have issues finding the PhysicsWorldSingleton

            EntityQuery query = entityManager.CreateEntityQuery(typeof(PhysicsWorldSingleton));
            if (query.IsEmptyIgnoreFilter)
            {
                Debug.LogError(" PhysicsWorldSingleton not found in ECSSubscene!");
               ```
#

I can even see these components added correctly to the entity.

So the issue seems to lie with the physics call from the player debug

summer night
#

#1 advice when learning dots is not to use chatgpt

#

it's advise is dated and never right

#

there is not enough dots source on the internet for it to generate good responses unfortunately

tulip moon
#

for sure, that's definitely something i've noticed. Im trying to do something rudimentary, like bridge the gameobject with the entities

#

Yea alot of videos focus on entity to entity communication which makes sense

summer night
#

claude 3.7 sonnet does slightly better when it comes to using modern API but having recently tested it again, it can't even answer a simple question correctly with modern dots "How to disable rendering"

tulip moon
#

Yea i tried using claude as well. both are not up too snuff. It makes sense because its just math algo not sentient AI.

hard to find resources for this specific thing i'm trying to do

#

It's decent at targeted questions not large blocks of code. i always have to revise

summer night
#

tbh my actual first rule of dots is to never access entities from a monobehaviour

#

only ever do the reverse and access monobehaviour from dots

tulip moon
#

O gotcha, so dots access mono, but not the other way around

summer night
#

you'll avoid a lot of problems doing it that way

tulip moon
#

that makes alot of sense. i def want the entities to use overlap which is gameobject based iirc, so in theory that should work and affect the player/non entity types

summer night
#

you can't use gameobject physics on entities

tulip moon
#

but can it do the inverse?

summer night
#

the 2 physics simulations do not interact

#

no, you can't use entities physics on gameobjects either

tulip moon
#

like can an entity call physics overlap sphere and affect gameobjects?

summer night
#

they are completely separate simulations

tulip moon
#

ah

#

ok that's a huge problem

#

so its pretty much "two planes of existence"

summer night
#

(gameobject physics is also disabled when subscene are open making it nearly impossible to continue to use if you're using unity physics)

tulip moon
#

hmm, so if I build my weapon system using physics overlap, it will never work with entities. and is only valid for things that are purely gameobjects like the oldschool method

#

I think i'm stuck on how the player will spawn an entity type overlap physics sphere

summer night
#

entities physics can do overlaps

#

on other entities

tulip moon
#

is there a hybrid approach? thats about all i got from gpt

#

or is that totally false. codemonkey videos seem to infer its possible to hybridize

summer night
#

hybrid is a requirement for most people

#

unless you want to recreate a lot of stuff (or use 3rd party libraries)

tulip moon
#

im thinking, the player spawns an entity compatiable overlap sphere at the same time it spawns the normal one. and itll fake the effect

summer night
#

but hybrid usually means your presentation (animation, audio, etc) is gameobjects

#

while your simulation remains entirely entities

#

this is where the whole, entities -> monobehaviour idea comes from

tulip moon
#

ya im not confident enough to move my player over to ECS yet. its still very weird

summer night
#

entities owns the simulation, it writes data to gameobjects to present it

tulip moon
#

interesting

summer night
#

now for the record, if you have a gameobject project that is already well in development

#

i generally don't recommend switching to entities

#

it's a huge mess

#

entities is much better starting as entities

tulip moon
#

does the player need to be in a subscene to use physics overlap entity stuff?

summer night
#

if you need performance, you can still use burst and jobs on critical paths in a gameobject project

#

without the need for entities

tulip moon
#

i havent built the enemy ai system yet, so i have alot of room to blend them

#

im trying to figure out the starting point for this current issue. im just using a brand new empty scene to try and understand the caveats and all that

#

im following 'entities and mono cannot communicate' but how to execute the entity physics overlap with a keypress?

#

in the code above, it looks like that's ECS specific from what i can tell. doesn't look like physics overlap with the standard mono

#

As seen here:
// ✅ Retrieve PhysicsWorldSingleton
EntityQuery query = entityManager.CreateEntityQuery(typeof(PhysicsWorldSingleton));
if (query.IsEmptyIgnoreFilter)

#

Do I create some kind of authoring on the player gameobject so it can use ECS compatible systems? And does the player then need to be added to a subscene?

Or will the player be fine in the scene (kind of need that for dependencies)

tulip moon
#

How do you go about adding that to a mono object though?

And can that mono be in a normal scene or does it need to be in a subscene?

trying to do the hybrid approach

#

an authoring script is mono from what i've seen so far.

Just a bit unclear on how to call this and where (scene/subscene).

if its not possible to call this from a normal scene and interact with a subscene, then i'll have to rethink alot of things

crimson tree
crimson tree
#

Entities physics are separate from gameobject physics. If you want to do entities you should keep your logic in ECS, and try to control the monobehaviours from ECS rather than the other way around. If you want to primarily have your logic be in Monobehaviours you should probably ditch ECS alltogether and just use burst (and possibly jobs) without entities instead.

tulip moon
#

hmm, im trying to see the bigger picture. most of my things use mono/poco.

something like Vrising is using ECS from what i've heard, but i'm not sure if that's also for the player characters themselves.

The entity to mono communication makes sense, being a one way thing.

Mainly looking at ECS for the ability to have alot of units on screen almost like a diablo/vrising situation.

The other issue is mono systems making references to the player to affect things like movement, or UI elements that may refernce the player in some way. That would all be invalid if the player became an entity from what I understand (they're all mono)

What would you recommend doing? It seems like ECS has alot of power in the cheapness of instantiation/rendering/etc. That would really help performance.

Though its starting to feel like ECS is meant for specific types of games.

Specifically RTS or games where everything is an entity full stop

crimson tree
#

ECS is an architecture, it makes no sense to mix architectures

#

Ecs has more benefits for certain types of games, but any game can be made using Ecs.

#

If you already have made your game using mono behaviors, and your game is set up with lots of references to logic in mono behaviors, then just using burst is probably your best bet. Find out what part of your code takes the most time, and rewrite it to use burst. For rendering, you can use gpu instancing without ecs too, which will probably benefit you the most if you're rendering a ton of units at once.

tulip moon
#

Would jobs/burst compiler work well with under 100-1000 units that use mono?

the idea is to have fairly rudimentary AI
(move, stop, attack, follow)

If that can be achieved with good fps at 100-1000 units that's good enough for me.

Most likely can even use pooling to help reduce some cost. I noticed that even rudimentary logic with alot of units gets laggy which is why i was turning to ECS

I'll definitely use ECS for RTS/tower defense type games where that's the main design (where everything is ECS from the ground up by design)

grand leaf
tulip moon
#

O gotcha, so only burst would work with mono? Trying to see what options I have with the standard mono workflow

#

ah, so based on what i've read, mono cannot be used with burst.
IL2CPP must be used though.

it says mono and il2ccp cannot be mixed, and its an either or situation

summer night
#

burst replaces IL, it'll work either mono or il2cpp builds

#

but you can't use managed code in burst, it has to be unmanaged

#

i think we're mixing up mono (compiler) and monobehaviours

#

mono behaviours will not work with burst as they're managed, they need to be converted to unmanaged data before passing to jobs

tulip moon
#

O gotcha. So mono cannot be used at all? Or can burst be used for things like unmanaged AI but still use mono for things like systems and the player?

#

Or is it all or nothing? Where if using burst, all systems must be made unmanaged since its global?

#

I.e. hybrid approach, or is it total commitment to one or the other*

glossy fractal
#

i have to make a post explaining all this crap sometimes because people repeatedly get tripped up by the name monobehaviour

tulip moon
#

Ah right. When i say mono i mean monobehaviour. Can that be used in hybrid with unmanaged systems. So part of the project uses jobs and burst but the other part uses the standard workflow. Is this possible?

glossy fractal
#

it depends, but you cannot talk about monobehaviours or gameobjects from bursted code

tulip moon
#

er, for example, i made my whole game monobehaviour, but only wanted the enemy AI to use unmanaged systems in order to use jobs and burst, is that possible? or does my entire game need to be restructured to use unmanaged systems in order to use jobs/burst to begin with?

#

for the most part i'll be using monobehaviours. just trying to see what avenues there are for performance when it comes to AI enemies and large swarms of units, maybe 100-200 on screen at once all executing scripts.

Sorry if i'm re-iterating my question. Just trying to be crystal clear. I'm only trying to use it for a specific use case. I know that AI/NPC/enemy logic will be expensive. I've already tried it with monobehaviours with ultra-rudimentary logic and it began to chug at the low hundreds

#

Based on your comment, it sounds like non-monobehavior can be offloaded onto jobs/burst, and I can still use the standard compiler/workflow for the rest and it will work just fine?

glossy fractal
#

yes, just so long as your data is unmanaged (e.g. you use nativearray, nativelist etc to store things). but people do that all the time in monobehaviour games

solar dragon
#

Bro save yourself a lot of trauma, go watch CodeMonkey's DOTS video ... he walks through everything you need to know in that ... You can find it on YouTube. Not sure I'm allowed to post links here. He also has comprehensive courses (free and premium) which cover how to make networked games in Netcode for GameObjects AND Netcode for Entities.

Definitely worth a look, it'll answer a lot of questions you have.

You can check out all of CodeMonkeys playlists here and choose something that interests you: https://www.youtube.com/@CodeMonkeyUnity/playlists