#Trying to move Object from A to B... since 3 days [SOLVED]

1 messages · Page 1 of 1 (latest)

pastel igloo
#

EDIT: this was solved, for a solution, see the end of this forum thread (full code example included).

I have watched the 1 hours DOTS 1.0 tutorial from Codemonkey now 3 times, then 2 times the dots 1.0 tutorial of TurboMakesGames. I read the DOTS 1.0 docs and understand the theoretical concept of ECS and DOD. But since 3 days now, i just simply want to move a unit from position A to B (multithreaded, using ISystem).

But i just dont understand how to apply this in code:

#

(above, is the current state).

rugged crypt
#

It should probably also be ref FollowPlayerSys followPlayerSys as you are writing to the transform

#

(I havent used Aspects much so having an Aspect in an Aspect might cause issues, i've never tried)

#

You could do ref TransformAspect transformAspect, in EnemyMoveSpeedCom enemyMoveSpeedCom instead if thats the case

#

You'll also want to send in the current player position.
(You could look it up inside the job but then i think you can't use the Aspect and would have to manually use the transform components)

#
[BurstCompile]
public partial struct MoveJob : IJobEntity
{
    //This attribute is from unity.collections namespace, there's other attributes called the same thing annoyingly
    // I'm not sure if this is necessary for these value types but i use it just to keepm track of what is RO
    [ReadOnly] 
    public float MoveSpeed;

    [ReadOnly]
    public float3 PlayerWorldPos;

    //Try with your aspect first
    private void Execute(ref TransformAspect transformAspect, in EnemyMoveSpeedCom enemyMoveSpeedCom)
    {
        //Do logic here
    }
}
pastel igloo
rugged crypt
#
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
    state.EntityManager.CompleteDependencyBeforeRO<WorldTransform>();

    // Presumably you have one player so you can get it as through the singleton api
    // PlayerTag is a empty component that you can add to your player (or use any other component which is only on your player)
    var playerEntity = SystemAPI.GetSingletonEntity<PlayerTag>();
    var playerWorldTransform = SystemAPI.GetComponent<WorldTransform>(playerEntity);

    var moveJobHandle = new MoveJob()
    {
        MoveSpeed = 1f, //move speed
        PlayerWorldPos = playerWorldTransform.Position

    }.ScheduleParallel(state.Dependency);

    state.Dependency = moveJobHandle;
}
#

I'd do something like that for now

pastel igloo
#

I am still trying to fully understand, but i understand the half of it so far already ElonMusk his will serve as a great example i will try to adapt to, thank you 💪

#

(the only point unclear is how this cross-reference works:

private void Execute(ref TransformAspect transformAspect, in EnemyMoveSpeedCom enemyMoveSpeedCom)

but i can figure that out i guess

rugged crypt
#

ref for RW, in for RO

pastel igloo
rugged crypt
#

So right now this job will go through all entities with TransformAspect and EnemyMoveSpeedCom

#

if you want to constrain that but don't need the component then at the top of the job you can do [WithNone(typeof(ComponentName))]

#

similarly there is [WithAll(typeof(ComponentName))]

pastel igloo
rugged crypt
#

and [ChangeFilter(typeof(ComponentName))] so that the job will only run on the chunk if there's been a write on that component this frame

pastel igloo
rugged crypt
#

yup, not relevant for your job though

pastel igloo
#

Ok and one last 2 questions:

  1. what if new job starts faster through OnUpdate(),than the ongoing jobs finish? Wouldnt this lead to a summing up of jobs??
  2. where did you gather the knwoledge, are there any other sources besides the docs or the currently few youtube tutorials available?
rugged crypt
# pastel igloo Ok and one last 2 questions: 1) what if new job starts faster through OnUpdate(...
  1. Jobs will always be done in the order that they are scheduled, this could mean they can go over frames but if you had a read job of the transform in this frame afterwards then this job will most likely complete this frame so that the next job can proceed. Basically you don't need to worry about it.

  2. Docs, experience and this discord (just reading through other peoples conversations when they come up can gain you a lot of knowledge)

pastel igloo
#

These are very valuable tips, and since you provided a code example, i am confident that i can solve it now, thank you very much!

rugged crypt
#

Just something i realised while typing you'll want to send in the time delta as well for the lerp

#

SystemAPI.Time.delta (think thats the syntax) can get it

#

and add [BurstCompile] to the top of your system and the OnCreate and OnDestroy

pastel igloo
#

regular Time.deltaTime does not work, or?

rugged crypt
#

and burst is free performance so always try to use it, entities is designed for it

pastel igloo
#

yes, i am aiming for max performance, thats why i take the struggle to refactor my already started game (made in mono and OOP), wanting to move atleast performance critical parts to DOTS

rugged crypt
#

hybrid is tough to do

pastel igloo
#

i thought its easier as i can use mono and dots : () ?

rugged crypt
#

imo hybrid is easy if you have the entities as the base system and then use gameobjects on top (renderering if 2D, or animation, UI) but keeping logic to ecs

#

the other direction is harder, as you have to separate systems and query between the mono world more

pastel igloo
#

i need to spawn few thousand enemies, so my plan was to convert these to entities and use dots for them, while for player i thought its ok to stay at mono and mainthread 🙂

#

Ok thank you very much!
If you dont mind, i will leave this thread open for some while until i get the code running

rugged crypt
#

yeah, feel free to ping me. Might not be around immediately to help though. Or just post in the #1064581837055348857

pastel igloo
#

No worries, i am already very lucky to receive help! Once object moves, i tip you a coffee over paypal 👍

pastel igloo
#

this dots is a fing mess... why i need even aspects, when there are already components, all these cross-references and many files to achieve just one thing.. i really hate it right now and would pass on it, if i werent dependand on dots.

echo plinth
#

you don't need Aspects at all, you can do same things with normal components

#

Aspect is like conjunction of many components which preferably work together like i.e. TransformAspect

#

it doesn't have any it's own data

pastel igloo
pastel igloo
echo plinth
#

Yes, you are correct. It's just fancy way of saying I want all components in this "bag"

pastel igloo
#

ahh ok, that clears some of the fog now around aspects

#

for now, i will leave them away to have less files to connect together in my head, but i think later they will be usefull

#

Ok that makes more sense now

#

thank you 🙏

echo plinth
#

np 😄

#

be sure to come back to aspects when you will be ready

#

they are useful for sure

pastel igloo
#

Before converting my mono player into dots, i have made a simple gameobject that shall serve as players position for testing. With aspects, i could reference the whole entity and then pull the transform, the line looks like this then:

public readonly partial struct name : IAspect {
    public readonly Entity entity;
    // ...
}```
(seen in this tutorial: https://youtube.com/watch?v=IO6_6Y_YUdE&si=EnSIkaIECMiOmarE&t=2806)

But how would i get the players position without using an aspect? This is the current state:
echo plinth
#

playerWorldTransform.Position?

pastel igloo
#

The code is from ThatDaniel, i am currently trying to adapt it to my scenario. It seems ThatDaniel used "WorldTransform" as a component on the player, but i do not have this

echo plinth
#

so what you have? Most of the times you would create query for entities you need. If you have only one player with a TagPlayer component on it code from screenshot is also good

pastel igloo
#

yes, on the left in hierarchy, there is the empty game object (entity) called "TagPlayer". But my IDE underlines this in red, saying "Type or namespace was not found"

echo plinth
#

and what does Unity console is saying?

pastel igloo
#

weirdly, it does not throw an exception on the TagPlayer part, only on the next one, which is fine, since that component is missing. So it seems that unity is ok with line 18, but my ide not

echo plinth
#

I don't know visual studio but can't you click RMB on that and fix it with menu? 😄

#

I meant in rider it shows me something like "import XXXX"

pastel igloo
#

Usually yes, but here it says no quick fix availbale : ()

echo plinth
#

try restarting 😄

#

strange thing is that unity don't recognize WorldTransform even with using Unity.Transforms

pastel igloo
#

errors still there : /

#

(after restart of IDE)

echo plinth
#

are you using asmdef?

pastel igloo
#

no

#

well not sure, i thought these are created by unity automatically, but i havent made some manually if thats what you meant

echo plinth
#

try restarting everything

#

in my case

echo plinth
#

and job of course

pastel igloo
#

oh youve tested it : () Good to know it should work (when playertag is not present), i will try to restart everything now

rugged crypt
#

public struct PlayerTag : IComponentData {}

#

and put it on your player entity (baker or add it via entity manager/ecb)

#

also in the OnCreate(ref SystemState state) add state.RequireForUpdate<PlayerTag>();

#

that way the system will only run if the player exists

pastel igloo
#

I have it like this now, next i will have to make the player component

echo plinth
#

oh sorry, didn't realised you didn't create component

pastel igloo
#

No problem, i didnt mention i think.

I am close to getting the changes done which ThatDaniel suggested, this is the current state. Atm i am blocked from adding the mono baker to the gameobject (currently trying to solve this)

#

screenshot showed the wrong code, here is the systems script:

rugged crypt
#

oh sorry it is

pastel igloo
#

correct, i copied it from the script when renaming the file

#

no worries, i also checked 4 - 5 times just to make sure, sometimes there are nasty typos that are not directly visible

rugged crypt
#

compile errors?

#

ah the system has an error?

pastel igloo
#

Just these regarding the ScheduleParallel, but no error that indicates the disallowance of adding my mono baker to the gObject

rugged crypt
#

comment out making the job for now or uncomment the playertag singleton stuff

rugged crypt
#

ScheduleParallel

#

not ScheduelParallel, oops

pastel igloo
#

ohh man what a nasty typo, i also missed that 😅
Just few messages ago i wrote "sometimes there are nasty typos that are not directly visible" haha

#

yes i was now able to add the monobaker to player

#

i am sorry i should have known this, this behavior is not only in dots, but in unity in general. My head is just exploding because of dots, so i miss even basic things atm : (

#

That worldtransform is still missing, but i now maybe able to get the player pos without that? (as i have a reference to the player now?)

rugged crypt
pastel igloo
#

Are you guys fine with how DOTS workflow currently is, or do you also hope for more simplifcation of things? For example the baking seems to be always the same step, this could be moved into a click of a button and into the background. I find DOTS a pure hell right now and hope for more simplification. OOP and Mono is no problem, i never needed help there in such extense like i currently do for dots. this is crazy, i have to smoke a cigarrete, my nerves are really triggered, imagine someone tries to simply move an object since 3 days now WhetMusk

rugged crypt
#

I think because OOP and monobehaviours are the complete opposite of DOTS, that makes it a steep learning curve to initially switch to.

#

the latest version of the ECS package has simplified a lot. SystemAPI is a blessing, removes so much extra code.

pastel igloo
#

Here in this line, i get a reference to the player entity, but how can i pull the position?

var playerEntity = SystemAPI.GetSingletonEntity<PlayerTagMono>();

Is this line:

var playerWorldTransform = SystemAPI.GetComponent<WorldTransform>(playerEntity);

a reference to here?:

rugged crypt
#

oh what version of the Entities package are you using?

#

that stuff is the transform system for v 0.51

pastel igloo
#

I wonder where all the other DOTS beginners gather, looking at this server and DOTS forum, all questions seem to be far more advanced, am i really the only one requiring help to this extend?

#

Wait i fetch the versions

rugged crypt
#

the new transform system in 1.0 pre-15 is WorldTransform, LocalTransform and LocalToWorld

pastel igloo
rugged crypt
#

If you click the entities package is there an update button?

pastel igloo
#

There is no upgrade button, so i checked "see other verssions" but still. Thats a good point because i already saw in docs that there must be version ending with .15

rugged crypt
#

what editor version are you on?

#

for the latest entities you need 2022.2.0b8 or higher

pastel igloo
#

(installed few days ago)

rugged crypt
#

huh, that looks like it should be able to run 1.0.0-pre.15

pastel igloo
#

i also have the Entities graphics package installed, maybe this has the entities ...12 as dependancy

#

(not sure, just a guess)

rugged crypt
#

does that have an update button?

pastel igloo
#

i will try to find a way to upgrade

#

i will check, hang on

#

checked, none of the associated packages have this, i will remove all and try to reinstall the packages from scratch

rugged crypt
#

if you choose the last one you can put the version in

pastel igloo
#

ohh thank you, thats a great tip!! i did not know this indeed

#

i just found that "Collections" package had an update, now it says burst has changed, i will restart unity, maybe i have more upgrade options then

#

it seems i am doing something wrong with the version

#

also tried this:

#

i am sorry, i do not want to steal your time, if you want to opt out, that is understandable ✌️

#

adding without version, it installs 1.0.0~exp.12 again

#

error found, i mistakened ~ in the version with -

#

By adding the version manually, i was able to get the newest versions installed.

Will now turn back to the code and see whats going on there.

#

WorldTransform is now known ✅

It now gives me new errors

#

(digging into these now)

#

After activating hierarchy, get new and very cryptic errors, that trace back into the entities library itself....

rugged crypt
#

you've put the monobehaviour and not the PlayerTag

pastel igloo
#

This is how the mono baker looks like, so i dont have "PlayerTag", only "PlayerTagMono" and "PlayerTagBaker".

#

When puttint PlayerTagBaker or PlayerTag alone into the getsingleton, i get errors again, as it does not recognise these

rugged crypt
#

you've called the tag PlayerTagCom so try that

#

its the IComponentData one you need to put in

#

it's in the other file

pastel igloo
#

my bad, i already forgot it existed as i always had the baker in mind

#

this is now accepted by ide, thank you

rugged crypt
#

you could have a script on your gameobject player to spawn the entity in Start()

rugged crypt
#

not in this case

#

bakers and subscene are useful for entity prefabs and other entity stuff

#

but theres nothing stopping you from spawning entities manually

#

you'll just be adding the components manually (or through a made archetype)

#

its a bit more effort

#
        private void SpawnPlayerEntity()
        {
            var em = World.DefaultGameObjectInjectionWorld.EntityManager;

            var playerEntityArchetype = em.CreateArchetype(
                            typeof(WorldTransform), typeof(LocalTransform), typeof(LocalToWorld),
                              typeof(PlayerTag));

            var playerEntity = em.CreateEntity(playerEntityArchetype);
        }
pastel igloo
#

My IDE still throws this error at the ScheduleParallel() call, something about boxing convention, but in unity, this vanished (but was there before)

#

While here, unity also noted the error:

#

"The type MoveJob cannot be used as parameter T..."

rugged crypt
#

try filling in the fields that you commented out

#

MoveSpeed and PlayerWorldPos

pastel igloo
#

Ok i did this;

#

i added _Position to

var playerWorldTransform = SystemAPI.GetComponent<WorldTransform>(playerEntity)._Position;

to get the position as float3 value, hope this is correct (was suggested by me IDE)

#

The error in IDE is still present, in unity, it miracously vanished for no reason while it was there before, and when running the script the job does not get even executed.

#

Thank you Krajca and ThatDaniel for the valuable help, i still take away some new things learned, but DOTS is pointless atm, i have to completely reconsider use of unity as it currently hinders me from advancing, even with mono, where i face unsolvable performance peaks.

#

** CLOSING WORDS:**
To prevent further wasting of other peoples time, i will now close this thread as it seems to lead no where, except to new errors, even if experienced people looked at the problem.

May this thread remain as an example of how fucking beginner unfriendly DOTS is (beginner in terms of DOTS, not unity or c#) .

Unless unity does not clean up what i consider currently a fucking mess, i do not see chance that me and probably most of average unity devs will opt over to DOTS.

To keep note:
all i wanted was moving an Object from A to B, in DOTS. Result after 3 days of intense trying: not working. Other people may have more success, but for the average unity dev this is a fucking hell.

#

Trying to move Object from A to B... since 3 days [UNSOLVED, F* DOTS]

pastel igloo
#

Trying to move Object from A to B... since 3 days [SOLVED]

rugged crypt
#

Is the OnUpdate running did you check that?

pastel igloo
#

EDIT:
i gave it a break for 2 days, after the initial salt has settled, i was able to solve it, given the input of the participants of this thread.

Incase other people looking for a solution, heres the final result:

Player component:

using Unity.Entities;
public partial struct PlayerCom : IComponentData {}

EnemyComponent:

using Unity.Entities;
public partial struct EnemyCom : IComponentData {}

...