#archived-dots
1 messages ยท Page 273 of 1
yeah that does not seem to be a lot of vectorized code
actually, is that even your code? doesn't seem like it. that's pretty much all from AllocatorManager.cs
yeah I think its part of my code its at the top but its not my code
like I said its difficult to figure out exactly where my code starts
get to the line where there's a comment that says your c# file name
yeah
cool
there's lots of nativequeue code like this just below though
that seems to be where the most time is spent in my job at least from what the markers indicate
there's tons of these yellow nativequeue lines
maybe thats the problem, Nativequeue isn't really good for what I want?
what are you trying to do again?
its a flow field type pathing system checking for all possible paths within an area
and native queue is used how?
I can show you
Marker.Begin();
while (indicesToCheck.Count > 0)
{
CellData curcellDat = indicesToCheck.Dequeue();
var deneigbors = GridCellHelperStuff.GetNeighbours(curcellDat.gridIndex, jobflowfieldat.gridSize.y);
foreach(int2 neigh in deneigbors)
{
CellData neigborCelldata = new CellData();//CelldataArray[indexneighpos];
for(int i = 0; i < PotentialMoveCells.Length; i++)
{
if(neigh.Equals(PotentialMoveCells[i].gridIndex))
{
neigborCelldata = PotentialMoveCells[i];
}
}
if (neigborCelldata.cost == byte.MaxValue)
continue;
if (neigborCelldata.cost + curcellDat.bestCost < neigborCelldata.bestCost)
{
neigborCelldata.bestCost = (ushort)(neigborCelldata.cost + curcellDat.bestCost);
indicesToCheck.Enqueue(neigborCelldata);
for (int p = 0; p < PotentialMoveCells.Length; p++)
{
if (PotentialMoveCells[p].gridIndex.Equals(neigh))
{ indicesToCheck.Enqueue(PotentialMoveCells[p]);
PotentialMoveCells[p] = neigborCelldata;
}
}
}
}
}
Marker.End();```
hmmm
well from posting that I at least realised one thing
I had one to many Enque()s
that will probably saves some cycles
You mean compared to SystemBase.GetEntityQuery() ? That one is cached.
and getting rid of that one Enque() seems to have reduced the time by roughly over 1500ms 
maybe it isn't such a good idea to use an nativequeue
Am I blind or does there not exists something like Mathf.Deg2Rad in the Mathematics package?
that seems like a huge decrease for such a little change. not sure what was going on there
correct. there's something much better. math.radians()
yeah maybe its just that expensive, and also it is processing that extra value which is just a waste of time
hmmm
when I instantiate a prefab
I kind of expect it to instantiate children as well
but they are not instantiated
is that supposed to happen?
Entity prefab
I thought I already asked this question before but I can't find it back with Discord's search feature.
When making an open world game with blocky terrain generated at runtime, can I use NavMesh APIs for the AI of hostile creatures who need to follow the players, or do I need to make my own pathfinding and link it to my character input components?
Also, here's another question I don't think I've asked before.
With Netcode for Entities, when the server creates an entity with ghost-related components in its server world, does it automatically tell the clients to create them? Either through RPCs, or simply by adding them to the next snapshots it sends (I don't know about their internals).
Is that a generic blobHash deserizalizer?
Someone has a reply for this ? I find it pretty interesting but I can't see how it can be done
Took me just a bit though xD
#archived-dots message
ping
I should have asked "should I use NavMesh APIs" rather than "can I use NavMesh APIs"
Keep in mind that this is an open world game
how can i measure cache miss in system? i want to understand if GetSingleton() before scheduling an Entity.Foreach() make missings ?
it gets singleton entity from query, not sure how cache miss is any importance
or may be find some explanation about this. I have a dispute with a colleague about this topic
[UpdateInGroup(typeof(ClientSimulationSystemGroup))]
public partial class CollectOwnedPlayerInputSystem : SystemBase
{
// ...
protected override void OnUpdate()
{
var ownedPlayer = GetSingleton<CommandTargetComponent>().targetEntity;
if (ownedPlayer == Entity.Null)
{
var commandBuffer = _entityCommandBufferSystem.CreateCommandBuffer();
var ownedPlayerId = GetSingleton<NetworkIdComponent>().Value;
var commandTargetEntity = GetSingletonEntity<CommandTargetComponent>();
Debug.Log("About to run Entities.ForEach");
Entities
.WithAll<PlayerTag>()
.WithNone<OwnedPlayerTag>()
.ForEach((Entity entity, in GhostOwnerComponent ghostOwner) =>
{
Debug.Log("About to run Entities.ForEach");
if (ghostOwner.NetworkId != ownedPlayerId)
{
return;
}
commandBuffer.AddComponent<OwnedPlayerTag>(entity);
commandBuffer.SetComponent(commandTargetEntity, new CommandTargetComponent
{
targetEntity = entity,
});
})
.Run();
return;
// ...
Why?
There's an entity with a PlayerTag, a GhostOwnerComponent, no OwnedPlayerTag, yet the Entities.ForEach above never runs
No
Debug.Log("About to run Entities.ForEach");
Entities
.WithAll<PlayerTag>()
.WithNone<OwnedPlayerTag>()
.ForEach((Entity entity, in GhostOwnerComponent ghostOwner) =>
{
Debug.Log("Running Entities.ForEach");
When I enter play mode with "PlayMode Type" set to "Client & Server" in the "Multiplayer PlayMode Tools" window, should I see logs of clients and the server in the console?
Are the created clients and servers even separate players? They seem to just be different worlds in the same player
If I should see server logs then I guess my server never sets client connections as in-game
Editor->Jobs menu should have a Full Leak trace option.
yeah, that is turned on by default for me
I didn't really find it
but it was result of switching from End ECB to Begin ECB
going back to End fixed leaks
but I can't figure out why
Hmm
Intel VTune, but getting detailed cache misses is kind of hard. for getting the singleton it's a sure one. once it's on stack and used it's all good
When instatiating a Prefab entity, a copy of the source entity is created with all components (and shared components), minus the Prefab component. It also seems not to copy system state components from the prefab to the new instance. Is this the intended behavior? The docs are not explicit about this.
Nah need to write it specifically
yes, State components and Prefab tags are removed
Ah thanks. I was looking at the ECB.Instantiate docs which is not as verbose.
also a tip: to instantiate whole hierarchy you need LinkedEntityGroup buffer component
I didn't know that, had to spent some time to figure out xD
Yes, thanks this I already knew. ๐ I tried to be creative with a system state component on the prefab to save an archetype change on instantiation. Guess that it currently not preventable.
But maybe I don't fully understand the archetypes yet, are system state and tag components not part of the archetype?
they are
Is there a way to reverse a query and see what component its querying?
ahem? As in provide a list of entities and figure out what they have in common?
GetEntityQueryDesc : "Returns an EntityQueryDesc, which can be used to re-create the EntityQuery." https://docs.unity3d.com/Packages/com.unity.entities@0.50/api/Unity.Entities.EntityQuery.GetEntityQueryDesc.html
GetEntityQueryMask : "Returns an EntityQueryMask, which can be used to quickly determine if an entity matches the query." https://docs.unity3d.com/Packages/com.unity.entities@0.50/api/Unity.Entities.EntityQuery.GetEntityQueryMask.html
More methods listed here: You might be able to find one for your use case: https://docs.unity3d.com/Packages/com.unity.entities@0.50/api/Unity.Entities.EntityQuery.html
hi guys, i have a NativeList<FindPathJob> findPathJobList = new NativeList<FindPathJob>(); throwing this error : The type 'Pathfinding.FindPathJob' must be valid unmanaged type (simple numeric, 'bool', 'char', 'void', enumeration type or struct type with all fields of unmanaged types at any level of nesting) in order to use it as a type argument for 'T' parameter
the struct is..
private struct FindPathJob : IJob {
public int2 gridSize;
public NativeList<PathNode> pathNodeArray;
public int2 startPosition;
public int2 endPosition;
public Entity entity;
public void Execute() {...}
does anyone know if there is a workaround so I can force it to allow this 'managed type'?
you can't have nativecontainers inside other native containers
but the better question i have is, why do you have a list of jobs?
I remember the code from yesterday and he's scheduling the list from a job which prompted my question, since when is that possible? on topic of that, I'd also not recommend that. just let the job work on an array.
that took an unholy amount of vector math
thanks for the tips guys, i just dont know how to apply it, ill keep trying and learning
collision camera?
yeah
i remember trying to do this myself with maths a while ago
i could not get it to feel nice
so well done as that looks great
i just use cinemachine 3rd person camera with a modification to use dots physics because lazy ๐ฆ
i maintain an asset since 2015. guess cinemachine has come a long way, last I used it (which was some kind of wipeout demo) it still had clipping issues and not many features
what do you mean by this sorry just let the job work on an array. as in remove the list completely and just run the job straight away?
build all your pathfind elements in an array and after all are gathered, schedule the job once and let it run on an that array.
ok, I thought that was what the code is doing ๐
for each entity, create a pathfinding job once thats done, run them all
you don't need to schedule a single job for every pathfind request. it's not really how it's supposed to work
i think yours might work nicer anyway
seems to 'predict' the collision instead of going, clonk, ok slide along wall now
yeah it does. started out as simple camera with a smart pivot like wow and then got quite a bunch of features were the most complicated one was the camera offset vector which many 3rd person shooters use. one of the tough things was to still keep the same point in the view because when the camera jumps around while aiming on someone, that's really annoying. ๐
I was thinking a lot if I should do a DOTS port but then I always concluded that the camera is still managed so there's little use
Anyone has any experience with saving?
I'm looking for a way to interface saving my data.
I need the most versatile system in this regard as possible
but I don't want to add for example interface to all component types that require saving
meanwhile also certain components actually mean, that some other component needs to be saved
For recent save I use [Save] attribute (and [SaveIgnore on fields]) for this
at work we just have containers per entity type - so each type of entity gets its own data container which is just what it saves, probably not flexible enough for you though
yeah, I am looking at your link in forum
as part of inspiration
but I'm still not sure if that's the best approach
so far I decided that I will save all entities that have PrefabDef class object component
which is basically just link to serialized prefab in XML
if you're writing a definition and attaching it
you could just use that to determine components to save
i don't find it as flexible as just generic saving though
<ShipDef>
<defName>Faster</defName>
<speed>0,2</speed>
<rotationSpeed>0,2</rotationSpeed>
</ShipDef>
<GraphicDef>
<defName>CapsuleShip</defName>
<mesh>Capsule</mesh>
<material>PlayerWhite</material>
<children>
<SphereHead>
<position>(0;0,57;0)</position>
<graphicDef>
<mesh>Sphere</mesh>
<material>Lit</material>
</graphicDef>
</SphereHead>
</children>
</GraphicDef>
<PrefabDef>
<defName>Player</defName>
<defs>
<defName>CapsuleShip</defName>
<defName>Faster</defName>
<defName>Wanderer</defName>
</defs>
</PrefabDef>
<ComponentDef>
<defName>Wanderer</defName>
<enableAI />
<addRandom />
<comp>WanderingAI</comp>
</ComponentDef>
here example of how I managed to make it work
GraphicDef is transform + RenderMesh hierarchy
i am slightly concerned about your performance though if you need to scale really large
ShipDef is unique def that adds unique set of components
like my approach, i can save 250,000 entities with hierarchies in < 20ms
ComponentDef adds tags by name
and deserialize in ~30 (of which 20ms is entity instantiate which i cant avoid)
and PrefabDef actually creates entity prefabs
I don't think I'll need saving of this many entities
but if you dont care about a) that crazy entity count or b) just hiding it behind load screens etc then its fine
flexibility for your game would be more important
yeah, versatility is key
since my biggest goal - maximum moddability
so anyone can inject their own dll with their own components, which will also be saved in simple way for modder
so far I see such options:
- I create special method in IDef and during save load, it'll assign/read all components
public void SetUpPrefab(Entity e, EntityManager em)
{
foreach (var def in _defs)
{
def.SetUpPrefab(e, em);
}
kind of like this
but with actually restored entities
but I find this option troubling, because that would mean I'll need not only to define this method for all defs
but also if for example X def needs saving of Translation + Rotation and Y def needs saving of Translation - I'll get duplicates
- I could try adding attributes, in which I could also link other component that needs saving for that component
But that would somewhat break ECS approach of data oriented
And also I won't be able to do that with translation, rotation and etc
When is your asset coming out tertle XD
when i go work on it again >_>
thought of doing some documentation and trying to setup some samples for testing
and noped out of there
tbh been too drained from work recently to actually do much of my own stuff ๐ฆ
bruuuuuh, I still couldn't figure out how to do saving
Is there a way to get untyped object of IComponentData?
object ?
Anything that can be serialized
no i mean object
or maybe get ready string
which can later be transformed back into IComponentData of ComponentType
DynamicComponentTypeHandle
but doesn't it require chunk to operate with?
well that's where IComponentData live
if you're using IComponentData, you're (in)directly using chunks
yeah, but I meant I need this just for 1 entity
allthough later maybe I can try to go into per chunk base
For now I basically have list of ComponentType and I need to figure out how to get serialized data from them
I am looking into it, but I just don't get it where is magic
how would you determine ElementSize
TypeInfo.ElementSize
var typeInfo = TypeManager.GetTypeInfo(typeIndex);
var elementSize = typeInfo.ElementSize;
hmm, I see
but that would give me what exactly?
this GetDynamicArray
array of whole chunk?
an array of each element yes
you should be doing this per chunk - every chunk will be the same archetype so they should all be saved
I just struggle to imagine how it's done
also, this gives unreadable result basically
I would prefer editable through hand result
yeah gl with that ๐ฌ
you're going to have to do a few things entities was not designed for
I assume it's simply impossible to get component without knowing type before compilation?
unless ofc it's byte array
what you probably want is
byte* ptr = EntityComponentStore->GetComponentDataWithTypeRO(entity, typeIndex);
and then convert ptr with
UnsafeUtility.CopyPtrToStructure<T>(ptr, out T value);
well i'd argue serialization is the conversion of data to a byte array
yeah, but with pointer I'm not sure how I can get
oooh
wait a second
Does ComponentType contain this kind of information?
it's already stored as a byte array
it's actually what made serializing entities so easy for me
didn't have to do anything
being unmanaged it's already in the format you need to write
now being readable that's a whole different problem
I'm ok with it being unreadable as long as I can simply read it back xD
EntityComponentStore where do I get this?
chunk?
hmm, nope
oh
I know what you mean, my brain is complete mush by the end of the work day.
hmmm
ISharedComponent can't nullable
that is sad
@rotund token sir, could you show how you desserialize that chunk data?
i just do the opposite of how i wrote it
I get it conceptually, but I have no idea what kind of methods you even use
{
var headerChunk = this.Deserializer.Read<HeaderChunk>();
var entities = this.Deserializer.ReadBuffer<int>(headerChunk.Length);
var components = this.Deserializer.ReadBuffer<byte>(headerChunk.Length * header.ElementSize);
for (var i = 0; i < headerChunk.Length; i++)
{
if (this.Remap.TryGetEntity(entities[i], out var entity))
{
this.SerializedData.Add(entity, (IntPtr)(components + (i * header.ElementSize)));
}
else
{
Debug.LogError($"Entity {entities[i]} wasn't found");
}
}
index += headerChunk.Length;
}```
oh you're more interesting in writing the data back?
I'm interesting in everything
if (components.Length == 0)
{
return;
}
var entities = batchInChunk.GetNativeArray(this.EntityType);
for (var i = 0; i < entities.Length; i++)
{
var entity = entities[i];
if (!this.SerializedData.TryGetValue(entity, out var srcStart))
{
continue;
}
var dst = (byte*)components.GetUnsafePtr() + (i * this.ElementSize);
var src = (byte*)srcStart.ToPointer();
foreach (var element in this.SaveChunks)
{
UnsafeUtility.MemCpy(dst + element.Index, src + element.Index, element.Length);
}
foreach (var offset in this.EntityOffsets)
{
RemapEntityField(dst, offset, this.Remap);
}
}```
i just loop all entities and see if they were saved
doesn't have to be used
could do a UnsafeUtility.AsRef and just write it as a component if you were doing it generic or something
kek
but that code above
is, apart from job boilerplate
the entire code in my deserialization for componentdata
i have similar code for buffers
and then a small chunk to instantiate the prefabs
and that's basically my entire system
the rest is just features
hmm
That made super confused
this.Serializer.AddBufferNoResize(components);
so that gives you NativeArray in some sort of list
I assume it's managed one?
Serializer is just a wrapper for NativeList
{
private NativeList<byte> data;```
like literally
ah
it just handles all the T to byte conversions
wait a second, then how do you later serialize that data
ah yes
i compress it and then write it to disk
How do you link it to entities? chunks or whatever?
effectively I write
key[]
component[]
where key is just entity.index
that is what i use as my unique key
yeah, but in the end all you have is byte array
out of where can I get keys for them?
if you notice the above code
var headerChunk = this.Deserializer.Read<HeaderChunk>();
i write a small header for each chunk
which is basically just Length
i.e. number of elements in this chunk
that byte array contains data other than componenets?
so my final format looks like
int Length
int[] Keys
T[] Components
oh i have layers of headers
thats per chunk
but there are multiple chunks per component right
so i have a component header
which is number of chunks, component type, saved component size (in case it has changed for migration) etc
then i have a header above this for number of components saved, type of compression etc
no I mean
how do you link that byte array
that's the part I don't get
that's all I have rn and I'm super confused
whole thing is in my above code
deserializing is slower because i read everything back 1 at a time
to validate it etc
when i load i create all entities i need to deserialize onto
store it in a hashmap<int, Entity>
where int was the saved entity index, Entity is the new Entity
then to deserialize basically i just loop both arrays (key, value) and check if the entity exists then store the data for it in a hashmap
Is that serialization or deserialization?
#archived-dots message
that's the 'apply' step
first code was deserializing
and storing the valid data into a hashmap
the second step was applying which is just literally looping every entity in the world and checking if they have data that was saved
and if so write it
wait a minute
so this byte array that you get from chunk
it contains entity array as well?
it slowly starts to make sense
so you made a struct which contains type/length, entitty (index) array and component (byte) array
Well I don't make a struct, I just directly write them to my stream
But yeah
Past bedtime, need to sleep
Hopefully that helped
Yeah, thanks
@rustic rain why XML instead of json?
everything is built in
attributes
names
just easier to write
I'll do saving in Json though xD
Only parsing XML is easy
writing is pepega
I dunno, json reading and writing is like one line of code with a strongly typed model. also json is faster than xml
json has no built in attributes support
I didn't see any attributes in your xml ๐ eh, if you like it more power to ya. i stopped writing xml parsers like 10 years ago in favor of json
for anything more practical I use https://msgpack.org/index.html then
and Json didn't look good at all in it
Should my non-Burst-compiled code use the Entities API's Method(typeof(T)) methods or Method<T>() methods when both can be used?
Method<T>() is probably better
As far as I know, Burst doesn't support RTTI or whatever it's called in C#, so I can't use typeof(T) in Burst code
it's just syntactic sugar
eh scrap that, if you need the type it's very different things
I would be surprised if burst doesn't support it. as long as T is unmanaged/struct it should work
both of these codes do very different things though. one gets the type as variable. the other is compiled with the types you actually use it for
It's basically dynamic vs static dispatch, isn't it
๐ค
public static int GetTypeIndex<T>()
{
var index = SharedTypeIndex<T>.Ref.Data;
if (index <= 0)
{
ManagedException<T>();
BurstException<T>();
}
return index;
}
public static int GetTypeIndex(Type type)
{
var index = FindTypeIndex(type);
if (index == -1)
ManagedException(type);
return index;
}
I never heard of this: https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@1.0/manual/index.html
I did
oh, this is not DOTS netcode?
I think it's DOTS Netcode ported to GameObject-based development
Actually nvm
It's more a port of the concepts/architecture than of the code
I think
yeah, seems it has nothing to do with burst/entities. man, I don't like codenames but having the same names for very different projects is even more annoying
They're not entirely the same names
"Netcode for Entities" (previously "Unity NetCode") vs. "Netcode for GameObjects"
ah they did rename it, I can only see "Netcode for Entities" in google ๐ well the problem I have is that it's still unity.netcode and the go one uses unity.netcode.gameobjcts which imples to me that gameobjects is built on unity.netcode. kind of confusing but if you know, you know
Nothing to do with DOTS
it's the new name for unity MLAPI
100% gameobjects
I agree very confusing naming ๐
all right, sir. I finally made some progress and now I'm at a stage when I need to attach byte array of components to entities. I have index hashMap, but I'm stuck figuring out what this part means this.SerializedData.Add(entity, (IntPtr)(components + (i * header.ElementSize)));
var components = this.Deserializer.ReadBuffer<byte>(headerChunk.Length * header.ElementSize);
What is this type?
Why does my server build log these errors (besides using the null graphics device)? Are shaders included in my server build?
ERROR: Shader HDRP/Lit shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/HDRP/DebugLightVolumes shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/HDRP/CameraMotionVectors shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/HDRP/GGXConvolve shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/HDRP/CharlieConvolve shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/HDRP/OpaqueAtmosphericScattering shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/HDRP/CustomPassRenderersUtils shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/HDRP/FinalPass shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Hidden/PostProcessing/SubpixelMorphologicalAntialiasing shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Sprites/Default shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
ERROR: Shader Sprites/Mask shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
I have these components in my server build configuration
Not sure what I should have
Not sure if it's normal that Unity warns me that the "Net Code Conversion Settings" component is "not used by the build pipeline"
If you want to build a standalone player for the project you must create a
BuildConfiguration- the regular build menu in Unity will not work.
The Netcode for Entities manual could be more helpful than that
It looks like the only place where the NetCodeConversionSettings build configuration component is used is here, in com.unity.netcode@0.50.1-preview.19/Runtime/Authoring/Hybrid/GhostAuthoringConversion.cs:
private static NetcodeConversionTarget GetConversionTarget(GameObjectConversionSystem system, bool isPrefab)
{
// Detect target using build settings (This is used from sub scenes)
#if UNITY_EDITOR
if (system.TryGetBuildConfigurationComponent<NetCodeConversionSettings>(out var settings))
{
//Debug.LogWarning("BuildSettings conversion for: " + settings.Target);
return settings.Target;
}
#endif
// Prefabs are always converted as client and server when using convert to entity since they need to have a single blob asset
if (!isPrefab)
{
if (system.DstEntityManager.World.GetExistingSystem<ClientSimulationSystemGroup>() != null)
return NetcodeConversionTarget.Client;
if (system.DstEntityManager.World.GetExistingSystem<ServerSimulationSystemGroup>() != null)
return NetcodeConversionTarget.Server;
}
return NetcodeConversionTarget.ClientAndServer;
}
What's the point of BeginSimulationEntityCommandBufferSystem?
sync point at beginning of update cycle
So 2 sets of structural changes per update cycle?
Netcode for Entities's CommandSendSystemGroup is part of the GhostSimulationSystemGroup which is part of the ClientSimulationSystemGroup
It would make sense for my system that collects player input on clients to run before the GhostSimulationSystemGroup so that the client doesn't wait for the next frame to send the collected input
This system gets the owned player from GetSingleton<CommandTargetComponent>().targetEntity
If it's set to Entity.Null, it tries to find a ghost player owned by the client, gives it a PlayerInput buffer, and sets GetSingleton<CommandTargetComponent>().targetEntity
This is done in Entities.ForEach using an entity command buffer
Then it returns so input collection is skipped for the current frame
But for when it does not return early because the owned player is found and so the input is collected, I want the system to run before the GhostSimulationSystemGroup
The system currently uses EndSimulationEntityCommandBufferSystem
Should the system switch to using BeginSimulationEntityCommandBufferSystem or not
I can't talk
What the fuck
The words don't come out
Nevermind
Ok I think I should use BeginSimulationEntityCommandBufferSystem by default and use EndSimulationEntityCommandBufferSystem when I don't want the changes to go unnoticed by the PresentationSystemGroup until the next frame
I read some logic for Begin and End to destroy entities but I forgot ๐ Maybe someone else remembers. solved some possible issues
Not sure if this means anything by itself
$ cd Library/PackageCache
$ rg -g '!*{Documentation,Test}*' BeginSimulationEntityCommandBufferSystem | wc -l
46
$ rg -g '!*{Documentation,Test}*' EndSimulationEntityCommandBufferSystem | wc -l
13
$ rg -lg '*/Runtime/**' BeginSimulationEntityCommandBufferSystem
com.unity.netcode@0.50.1-preview.19/Runtime/ClientServerWorld/ClientServerWorldAllocatorResetSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Rpc/RpcCommandRequest.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/GhostSendSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/PredictedGhostSpawnSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/GhostReceiveSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/GhostDespawnSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/NetDebugSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Rpc/RpcSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/Prespawn/PrespawnGhostInitializationSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/GhostSimulationSystemGroup.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Connection/NetworkStreamReceiveSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/Prespawn/ServerTrackLoadedPrespawnSections.cs
com.unity.netcode@0.50.1-preview.19/Runtime/NetCodeDebugConfig.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/Prespawn/ClientPopulatePrespawnedGhostsSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Connection/NetworkStreamCloseSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Connection/HeartbeatSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/Prespawn/ServerPopulatePrespawnedGhosts.cs
$ rg -lg '*/Runtime/**' EndSimulationEntityCommandBufferSystem
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/Prespawn/AutoTrackPrespawnSection.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/SwitchPredictionSmoothingSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/GhostDistancePartitioningSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Snapshot/GhostSendSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Rpc/RpcSystem.cs
com.unity.netcode@0.50.1-preview.19/Runtime/Rpc/RpcCommandRequest.cs
Netcode for Entities prefers BeginSimulationEntityCommandBufferSystem
Does anyone know if there's some way to update a RenderMesh's mesh from within a job?
I vaguely remember that there was an API for this, but I can't seem to find it now.
you can get the nativearrays from a mesh and manipulate that
technically you can actually get shared components in a job when you're not in burst (and I even wrote a SharedComponentDataFromEntity container for this)
but you're going down a pretty rocky road if you do this
Thanks, what's the API for getting the NativeArrays from the mesh? I don't see an obvious way to do it.
I'd like to keep things bursted if possible.
Sorry I meant there are overrides for writing to a mesh from native array*
SetVerticies, SetUVs, SetIndices etc all have native array overrides
Ah okay, so does that mean I have to calculate the mesh in a job (which I'm doing now), and set it on the main thread?
yes unfortunately you need to write the final mesh on main thread, however you can speed this up a bit with MeshData
Thanks very much, I'll give that a try. ๐
it lets you write all the verts etc to the mesh in a job
but you still need to call
Mesh.ApplyAndDisposeWritableMeshData(dataArray, mesh);
to finalize it on the main thread at some point
Ah, it was the MeshData API that I heard of before but couldn't find again.
Thanks again for the help.
can i get array of values from NativeMultiHashMap?
is there a better way to have array of values per Key?
in my case Entity is the Key and I need array of floats
if that helps
GetValuesForKey
if you want an array you'll just have to iterate it and populate it yourself
sorry not sure what you mean
when I put the values in order
would I get the same order while reading?
or reversed
or it would be random
you mean put values into hashmap
you should consider order random for a hashmap
if you dont remove an element then i believe it'll be reversed
but you shouldn't rely on this behaviour
so Can I store values in something else to preserve order?
Hello all it's been a long time since I played around with dots and slowly getting back just for the fun of it.
I remember that [BurstCompile] attribute applied to static function actually caused the burst to compile it. is it still the case?
If so is there a reason why those functions don't show up in burst inspector?
oh yeah I think NativeStream would be enough
wtf lately I figured out that NativeStream is best container ever
you also need to apply it to the owning class
I mean it's just so versatile
neat little trick for entity as key is to just use an int as key type and the index, saves one integer, the version.
nativestream is great for that, especially when it operates on the same query, then the data is ordered and you don't even need to index really
would require that every entity has the same amount of data though, otherwise it'll misalign
I've also tried indexing entities myself for when another query needs it. i've mostly found better solution for this. it's quite fast to do and can come in handy
IJobEntityBatchWithIndex
nativestream has the restriction that you can't write to the same index due to the memory block design and there's no good way around it (which is usually fine when the chunkIndex or entityIndex is used) for non-linear writes this could be interesting and I think I can make this work with the parallel list
parallelParallelList? ๐
could be a huge save when I manage to apply this to some of my code paths and I don't need to write out arrays and make a hashmap ๐ค
Now that AddHybridComponent is gone, how are we meant to do hybrid things?
sir, could you explain what is SaveChunks in this context?
foreach (var element in this.SaveChunks)
{
UnsafeUtility.MemCpy(dst + element.Index, src + element.Index, element.Length);
}
thats what it simplifies to if there is no [SaveIgnore]
hold on, unity is opening
also, what is
SerializedData
is that (Entity, IntPtr) dictionary?
var components = this.Deserializer.ReadBuffer<byte>(headerChunk.Length * header.ElementSize);
And this
I don't really get, what is it
<Entity, IntPtr>
this.Deserializer is just the opposite of Serializer (except just a native array)
it just holds the byte array
foreach (var type in _typesToSaveWrite)
{
var elementSize = TypeManager.GetTypeInfo(type.TypeIndex).ElementSize;
var dynamicHandle = GetDynamicComponentTypeHandle(type);
foreach (var chunk in chunks)
{
var components =
chunk.GetDynamicComponentDataArrayReinterpret<byte>(dynamicHandle, elementSize);
if (components.Length == 0)
{
continue;
}
var entities = chunk.GetNativeArray(entityHandle);
for (int i = 0; i < entities.Length; i++)
{
var e = entities[i];
if (!componentPtrMap.TryGetValue(e, out var srcStart))
{
continue;
}
var dst = (byte*)components.GetUnsafePtr() + (i + elementSize);
var src = (byte*)srcStart.ToPointer();
UnsafeUtility.MemCpy(dst, src, elementSize);
}
}
}
here's what I did
and that seems not to work
no errors, but entity position is not restored
and always defaults
is it running the actual memcpy
because it looks fine i think
this is wrong
var dst = (byte*)components.GetUnsafePtr() + (i + elementSize);
needs to multiply
var dst = (byte*)components.GetUnsafePtr() + (i * elementSize);
foreach (var savedChunk in savedType.chunks)
{
var legnth = savedChunk.entities.Length;
var entities = savedChunk.entities;
var components = new NativeArray<byte>(savedChunk.dataArray, Allocator.Temp);
var compsPtr = (IntPtr)components.GetUnsafeReadOnlyPtr();
for (int i = 0; i < savedChunk.entityCount; i++)
{
if (remap.TryGetValue(entities[i], out var entity))
{
componentPtrMap.Add(entity, (IntPtr)(compsPtr + (i * savedType.elementSize)));
}
}
}
Here how I create source pointer
what about getting pointer?
One remark, I serialize to managed byte array
and then recreate NativeArray from it
is that ok?
ooooh, ok
now that I swapped + to * it works
hmmm, now gotta figure out that thing for sharedcomponents
allthough, it's just integer
Any idea what is faster?
EntityManager's GetComponentData or GetSharedComponentData?
both are just integer wrappers
Hi there,
How can I get started with Unity Dots?
A good guide
https://dots-tutorial.moetsi.com/
Unity manual is a must to read
https://docs.unity3d.com/Packages/com.unity.entities@0.50/manual/index.html
Can I use unity dots with my individual free license of unity?
this is for ECS tho
what is that ๐
smth way more fun than OOP
you don't have to use ECS for dots tho
there are also jobs and burst
Is it worth to get into dots for an indie solo developer?
or should I continue with the native one?
i'd say most (not all) are indie developers in here
depends entirely what your objectives are
and how much you enjoy coding vs making games
what are you implying? xD
I am targeting from low end pcs to high end consoles.
nah, it's more about
what kind of game do you have in mind
if it's some kind of large simulation
Multiplayer war game
and also a simulative game of a city builder
but it's still alpha, so you'll have to create everything by yourself from scratch (almost)
city builder sounds good for ECS I think
a lot of people who currently use dots do so because they like spending hours optimizing and getting the most
as it is still a preview, it currently does not have the same tools and usability as regular unity so if you're unfamiliar and new to it, it might take a lot longer to build your game.
hence i ask if building games or coding is your focus
Currently I am doing it with URP but the fps dosen't even touch 20 on i5 with no graphics card
render pipeline is not really related to dots
you'll have to use either urp or hdrp with dots ecs after all
I don't want to launch my city game rn but have some 3-4 years of planning on making it perfect before launching it ๐
anyways, I suggest just to try and read manual
it'll give you concept ideas
what ECS in Unity is about
I would prefer with urp cause hdrp will break my system hot.
hmm, any idea how can I make some sort of message system for ECS?
Basically I have certain systems, that have public methods that are widely used by other systems. Can't avoid that.
What I'd want - make it so there's a way to call it as simple as CurrentWorld.CallXMethod
Instead of having to save those systems as fields in every other system
some kind of Buffer could do the job, without structural changes
my point stays though
If you have a lot of things to instantiate, enqueue or etc
Using entities/adding components for that would not be great for perfomance
Collision system is using buffers
For example
dont get tricked, performance is relative
some of the people writing these systems are testing on 250k entities
most games are going to have 1/1000th of that
Do I remember correctly that enabled/disabled components will be part of 1.0
Or at least that's the plan for now
I'm kind of used to not having them already xD
What I can't wait for: getting rid of RenderMesh components
some dev said they will use smth else
you'll have to pre-register all your meshes with the hybrid renderer
im not really understanding how that will change
rly? I've done my renderer this way ๐
i believe so
oh I get it now
they showed us the tech
here
yeah
This means that you can't directly reference objects such as instances of Mesh and Material, and instead, you need to register them with the BRG before you use them
this is why i'm asking because if anything, I feel like this would make it harder for modders.
why would it?
now we dont know how they will set it up
but imagine you have to be setup via a subscene or something on game launch - this is unlikely but i'm just pointing out how a certain work flow could make it worse
you can dynamically load meshes at startup and register them
I assume there will be such possibility
in my solution I don't have any mesh/material on my entities so there is no managed components
only tag component identyfing how should I render this
of course it strategy game
so I can assume few things
that's much more ideal because it means you can easily strip rendering from servers for client/server games
but that's hardcoded solution
it works, just not everywhere
so what is the problem? ๐
im not saying there is a problem
for now it is hardcoded but i'm still on 0.17 so I don't have source generators afaik
^ like how does it change anything
oh, I didn't really mean it about pre-registering
allthough
registering meshes and materials
sounds like interesting idea
1.0 going to break all our projects ๐
maybe you should fix it ๐
idk how, I reported it as bug to unity
I just don't see any solution
because all stack trace is going towards Unity TRS system
interesting
i wonder what you're doing wrong
havent seen an issue in there in a long time
changing parents?
only time i've ever seen people have issue with TRS is them doing parenting
Don't you need to change LocalToParent also?
i think it happens when you change parents in same frame or something
and the PreviousParent system state hasn't had a time to cleanup or something
never had the issue myself, just seen it rarely reported
basically something like reparenting causes issues
is IJobEntityBatchWithIndex with ComponentTypeHandle<> better than IJobParallelFor with Query.ToComponentDataArray<>?
yes
it's chunk array vs all entities array
Query.ToComponentDataArray<>
is just doing a batch iterate and copying it to array
how? both are using query
IJobEntityBatch is giving you batchInChunk
from which you take componentData
vs you get Array from whole query
smaller array -> smaller cache miss
but then I use the whole array so where are those misses?
no idea, how that low level stuff works
so anyway
Can I assume that if I use data from entity it's always better to use IJobEntityBatch?
or .ForEach() if it's enough
in 98.7% of cases yes
Do you guys prefer methods in component structs, extension methods or some other way for functionality that is related to a component and should be reusable and why?
that's somewhat against Data Oriented Design
There's nothing about reusable logic that goes against DOD. It's just good software engineering practice.
I mean having methods in structs
If they modify the struct, then yeah, but static methods are a good way to organize code.
yeah, I use static Method(this T kek) for such cases
helps with organisation as well
Yeah, that's the best way to go IMO.
No reason to have files full of free functions IMO. We're not programming in C any more.
Thats why I am asking. Whats the reasoning/advantage of moving the methods into a separate file?
Its still technically part of the struct as it "extends" it ๐ค
well, for one
Component structs usually is just data, that can be accessed from any sort of system
so by putting any logic in separate class
you follow DOD design
avoid clutter
nothing stops you from having methods in structs though
if it's specific struct that was designed by you for it
why not?
If a function applies to a specific struct, it should live with that struct.
The advantage of the extension methods could be that you can have multiple files extending the struct. So you can have Assembiles that add the extension methods that are used by that assembly for that component
@rustic rain do you have any kind of naming convention for your extension classes?
VectorUtility
MathUtility
PepegaUtility
xD
nothing fancy
if it's system specific
hmm
I haven't had such case yet
kind of tend to have such methods as generic as possible
I have weird problem where a job seems to be taking excessively long I'm not sure what's the problem or how to solve
when searching an 18 by 18 grid it takes roughly 101ms, whereas at a 20 by 20 grid it takes 610ms
is burst on?
yep
how many if do you have in job?
Thx for the input @rustic rain and @woeful comet. Will keep that in mind
4 ifs
can you bring it down to 0?
I'm not sure how 
its weird at lower values the time it takes doubles each time(which seems normal)when the grid gets one bigger but at the 10 value it gets inordinately longer
have you thought of implementing quadrants?
I kind of do have a rough sort of that thing, it exits early when its searched usually less than half of the grid
maybe try brute force?
the job was roughly 2000ms at 20 by 20 now its down to 600ms
no early returns and etc
literally go through all data
and only then return correct result
gotta see if I can get it down further
Why does Rider tell me that the partial keyword is redundant when it knows that the class is a Unity ECS system
I am kind of brute forcing, but will see if I can get rid of some of the ifs, thanks
you should also take a look at burst analyzer
I never used it myself
but it shows that burst code gen
are you latest rider? it usually fixes itself on recompile
in which you might get an idea whether result code is good or nah
you mean the burst inspector
yeah that stuff is really hard to read 
Rider 2022.1.1
And in Unity I have the "JetBrains Rider Editor" version 3.0.14 package installed
It's the latest version
So uh, there have been whispers that Unity dots helps with large entity counts, is this true?
yeah
hundred thousands entities and etc
Does it work in 2D?
Can you recommend a starting point video?
except solving the million dollar problems of IT
who knows
maybe one day...
if you solve them one day... you gotta tell me first before you publish it ๐
Anyone know if PUN/Photon will work with entities/DOTS?
can you make it work? -> probably
would it make sense? -> absolutely not
Is DOTSNET the best option then?
i have no idea what DOTSNET is
there is / will be a full dots networking package though
Are you referring to Unity's networking solution?
I've heard it's not fully fleshed out and as well documented as existing solutions
there's not THE unity networking solution. they have multiple now.
you are probably referring to Unet.....which has been deprecated ages ago
the new ones are pretty damn good and solid
https://docs.unity3d.com/Packages/com.unity.netcode@0.50/manual/index.html
there's netcode for gameobjects (self explanatory)
then there's netcode for dots (link)
then there's unity.transport (low level, everything doable pretty much)
like even for normal gameobjects, after working with netcode for gameobjects for a while, i cannot recommend photon or mirror or whatever anymore
imo
Understood. Are you bucketing DOTSNET in with photon and mirror as well? How does DOTSNET compare to Unity NetCode for DOTS?
I'm reading through the documentation right now. But looking for some opinions as well ๐
When should a system be put in the InitializationSystemGroup?
Where should my server choose a seed for my procedural terrain generation? In a system that is destroyed after updating once? In the OnCreate on my terrain generation system?
I want it to automatically be done when the server starts
OnCreate and parse an args argument from commandline
[InitializeOnLoad] is probably fine too to parse the argument. I'm not sure if the system is already created then, I don't think so, you'd have to test for that
Ok thanks
wtf
_allSystems = GetEntityQuery(ComponentType.ReadOnly<StarNormal>(),
ComponentType.ReadOnly<StarShared>());
it's not assigned into this query
Does that entity have the Prefab or Disabled tag components on it? Those are excluded by default. Based on the entity name, looks like a prefab.
no, it's not
it's instantiated
from prefab
I am really confused, I am assigning these 2 components to all entities in child hierarchy. But children don't get assigned ๐
public static void SetStarComponents(this EntityManager em, in Entity e, int ind)
{
var starNormal = new StarNormal() { systemID = ind };
var starShared = new StarShared() { systemID = ind };
foreach (var child in GetAllEntitiesInHierarchy(e, em))
{
em.SetComponentData(e, starNormal);
em.SetSharedComponentData(e, starShared);
}
}
public static IEnumerable<Entity> GetAllEntitiesInHierarchy(Entity parent, EntityManager em)
{
yield return parent;
if (!em.HasComponent<Child>(parent))
{
yield break;
}
DynamicBuffer<Child> buffer = em.GetBuffer<Child>(parent);
foreach (var child in buffer)
{
foreach (var anotherChild in GetAllEntitiesInHierarchy(child.Value, em))
{
yield return anotherChild;
}
}
}
Does it actually have child buffer
So are you not getting an error?
I did not just set parenting, I also created child buffer
You seem to be looping a buffer and calling em set shared component
hm
Which would invalidate the buffer
Don't think so
It just calls that method once, yields, runs your code
Back into method
Same reason you can't foreach a dictionary and remove an element - invalidates the foreach
var hierarchy = GetAllEntitiesInHierarchy(e, em);
foreach (var child in hierarchy)
{
em.SetComponentData(e, starNormal);
em.SetSharedComponentData(e, starShared);
}
I even tried this, same thing
hmm
hmmm
That doesn't change anything
I'll convert to array
You need toarray or something
to test
That said if it was actually iterating it should error
So if you're not getting an error I feel like it isn't iterating
Have you stepped through?
what
me
so dumb
but that still doesn't fix broken children getting
hmm
it only returns parent
even though there is certainly a children
at very least because I instantiate from this prefab
and it has linked entity group
Your get all entities in hierarchy seems wrong to me
but I need it
I don't return child, because I return parent
and then call same function on child
in which it becomes parent
Oh I missed that part
That seemed an odd way to write it
But yep you want to return original parent as well
no
ok
so child buffer
is removed for some reason
after instantiation
bbbbbbruh
and how am I supposed to restore it
seems like an old issue
ok, so I still have LinkedEntityGroup
maybe I can restore hierarchy myself
sooo
how can I call method with burst?
[BurstCompile]
private void RestoreChildHierarchy(NativeArray<Entity> entities)
{
for (int i = 0; i < entities.Length; i++)
I did some monstrocity
and I need to make sure it runs bursted
has to be static to start with
and you can't pass native containers to burst methods
(you can't pass structs except if it only has 1 pointer field in it)
no
primitives and pointers only
just like you were talking to native code
(which you are)
var list = new NativeList<Entity>(Allocator.Temp);
for (int i = 0; i < entities.Length; i++)
{
var e = entities[i];
var buf = EntityManager.GetBuffer<LinkedEntityGroup>(e);
list.AddRange(buf.ToNativeArray(Allocator.Temp).Reinterpret<Entity>().GetUnsafePtr(), buf.Length);
}
When I dispose list, will buffer be safe?
and also will those NativeArrays that get reinterpreted disposed if I dispose list?
Do I even need to do toNativeArray?
Do you know the correct way to destroy a companion object without destroying the entity?
When I spawn one in netcode I get 2 instances on the host so I need to remove the game object, the entity however should stay as its ghosted position is required for the client companion object.
When I try to delete the companion object the companion transform system complains because its trying to look them up with entity references like everyone else
hm, isn't the real problem that 2 instances are spawned? doesn't sound right. if you have a transform on the entity you can destroy the transform.gameobject and then remove the transform component
This is normal in netcode on the host.
Normally one entity goes to server world and one to client world.
But companion objects dont live in a world, so you get 2 in the same scene
why does a server spawn a companion object? isn't it client only?
hmm, I see what you're saying...
Its part of a ghost prefab. So maybe I could replace it with a client only spawner instead and hook up the parenting afterwards on the client
Netcode makes things twice as complicated as they ought to be but I guess that comes with the territory
yeah, there's an attribute so a system runs only on client, server or both. if you set this to client for the spawner it should work out
oh yeah
its a huge problem when you run things like multiple clients on same machine
you get like 2x lights etc in the scene
i specifically avoid companion objects on ghosts
how you gonna do nameplates? runtime spawn them?
what do you mean by nameplates sorry?
sure, don't put them on the ghosts
little name tag above the players head
probably render them from code instead of UI
my draw system can already draw text really nicely in world
(mostly just for performance)
but if i didn't do it from code i'd probably just spawn them when required from a pool i think
i haven't considered it though
Interesting, was wondering how you go about these rough edges in DOTS
thanks a lot, turns out my code wasn't bursted at. So now I look at new performance number and my mind is blown
is there a bursted implementation of sort function for NativeArray/List? Build-in one seems not to be bursted
it's bursted if you call it in burst code ๐คฃ
yeah, asked the question and started to actually look at the attributes %)
burst or not, depending on how many elements you have in the list, sort is slow
well burst turned 3.5 ms into 0.43 ms, so I'm happy
I have to say I'm as always amazed with burst performance, it allowed me to calculate vision cone against 10k edges in sight in 1.5 ms whereas without burst it was around 5
and once I get to manual vectorization I expect it to become even less
yeah burst is amazing. 10x speedups are pretty normal
sometimes even more, kind of crazy
I just don't get it
_allSystems = GetEntityQuery(ComponentType.ReadOnly<StarNormal>(),
ComponentType.ReadOnly<StarShared>());
I have this EntityQuery
StarShared is Shared Comp
if that matters
EntityManager.AddComponent<DisableRendering>(_allSystems);
I do t his
some entities are unnaffected
There it is
It's not part of that query, and has no relationship with SetRenderingSystem from which this query exists
and no, it's not prefab
Meanwhile, here other and it IS affected
absolutely no difference
WAaaaait a second
oh my god
I figured it out
_curSystem = GetEntityQuery(ComponentType.ReadOnly<StarNormal>(),
ComponentType.ReadOnly<StarShared>());
_allSystems = GetEntityQuery(ComponentType.ReadOnly<StarNormal>(),
ComponentType.ReadOnly<StarShared>());
they are same
and _curSystem is getting filters
should have simply created new
Any tip where can I find manual on loading/unloading subscenes?
I need to have full control over what subscenes are loaded, what subscenes are not loaded
Manual no, but did you check the subscene demo? I would guess it would explain a lot, but I did not check.
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/Advanced/SubsceneWithBuildConfigurations
poorly documented
is that good?
also, can't find how can I stop subscene from loading by itself?
this.Entities
.WithNone<RequestSceneLoaded>()
.ForEach((Entity entity, int entityInQueryIndex, in SceneSectionData sceneData, in LoadWithBoundingVolume load) =>
{
var boundingVolume = (AABB)sceneData.BoundingVolume;
var maxDistanceSq = load.LoadMaxDistanceOverrideSq > 0 ? load.LoadMaxDistanceOverrideSq : loadMaxDistanceSq;
foreach (var ltw in playerPositions)
{
var distanceSq = boundingVolume.DistanceSq(ltw.Position);
if (distanceSq < maxDistanceSq)
{
buffer.AddComponent<RequestSceneLoaded>(entityInQueryIndex, entity);
return;
}
}
})
.WithReadOnly(playerPositions)
.ScheduleParallel();```
this is how i load subscenes within range of a player
reverse is just removing RequestSceneLoaded component
ahem
I'm confused
So, all subscenes inside loaded normal scene will be loaded
that seems clear
so, instead I should remove that subscene
and load it manually?
subscenes can actually be made up from multiple sections
each with its own bounds
by default all subscenes will have 1 section
and this is where your entities actually live
(but you can break them up further into more regions if you wnat)
to load a section all you need to do is attach RequestSceneLoaded to the section
if you look at your SceneSystem.LoadEntitySceneAsync
what it's actually doing is
{
RequestSceneLoaded requestSceneLoaded = CreateRequestSceneLoaded(parameters);
EntityManager.AddComponentData(sceneEntity, requestSceneLoaded);
if (parameters.AutoLoad && EntityManager.HasComponent<ResolvedSectionEntity>(sceneEntity))
{
foreach (var s in EntityManager.GetBuffer<ResolvedSectionEntity>(sceneEntity))
EntityManager.AddComponentData(s.SectionEntity, requestSceneLoaded);
}
}```
adding RequestSceneLoaded
to all it's sections
no
hmm, could you recommend any specific pattern for bootstrap?
rn subscene is just loaded, which I don't want
that's kind of a broad question
What I want - is to load all subscenes manually
Basically I have a World subscene which is supposed to be loaded only when world is getting generated
and several subscenes that I would want to load/unload on demand
i have a script i attach to all subscenes which tells it how it should load
AutoLoad
Range
Custom
(range is what you saw above)
hmm
when i start a world, i then load all AutoLoad subscenes and i make the world not tick until they're loaded
(so i don't have to through dependencies in all my systems - these are mostly my settings, prefabs etc)
Do I need any special settings for mono behaviour script execution order for this?
what do you mean
rn, no special scripts or systems
from what I noticed
they are loaded in async
and sometimes even during OnStartRunning
they might be not loaded yet
so, when and from where are they even scheduled to be loaded?
first of all I am looking for a way to stop them from loading alltogether
so I can try and do that manually
also what bothers me is that normal scene is also loaded as entity
theres a toggle on them called auto load
untick it ^_^'
๐คก <- this is me
hi everyone,
since there's no update of DOTS Animation for 0.5, how can I animate models on a scene ?
through hybrid solutions (keep gameobjects synced with entities) or write animation yourself
any tip how I can differ between scenes? It seems like entities by itself contain little to no information about actually what scene is it.
Not sure how I can figure difference between this scene and another
you mentioned adding some data to scene game object
But I don't really see how it's data can be passed to entity
unless ofc, IConvertGameObject interface works on subscenes
I setup all my subscenes when I create my world
I need to load my auto loads as well
I get it, but what is tying game object with entity in this scope?
can ConversionSystem catch it?
or IConvert interface?
Nothing
how do I know whether this entity is scene I want?
There is no entity
Until you create it via loading the subscene
I think you can just set the flag don't load or something like that to instantiate the sub scene to create its entity but not load its assets.
(in bed sorry can't check api, time to sleep anyway )
but it creates scene entity even if I untick Auto Load Scene
To which system group should a character controller system implementing basic physics belong to in a game that uses Netcode for Entities?
I want clients to predict their owned player's movement
But GhostPredictionSystemGroup does not belong to FixedStepSimulationSystemGroup, to which physics systems should belong afaik
I guess I'll put the system in FixedStepSimulationSystemGroup and make it retrieve the GhostPredictionSystemGroup to get the predicting tick anyway
I don't know how I missed this, thank you
I cannot more highly recommend using Rival if you want a good DOTS character controller out of the box.
But even if you wanna do it yourself, Rival discord is a good place to ask, Philippe StAmand knows character controllers in DOTS better than anyone else.
Rival discord
Link?
Nvm I found it
I have 2 problems
- Creating a
Unity.NetCode.PredictedPhysicsConfigsingleton on both the client and server does not move physics systems to thePredictedPhysicsSystemGroup
- I can't manage to do a raycast that collides with my procedurally generated terrain
Ok I noticed something
Are you using entities 0.50?
How do you create your singletons? I do mine immediately after I create the worlds.
Yes I am using Entities 0.50.1-preview.2.
I create my singletons with a system, not inside my bootstrap:
[UpdateInGroup(typeof(ClientAndServerInitializationSystemGroup))]
public partial class NetcodeConfigSystem : SystemBase
{
protected override void OnStartRunning()
{
var netcodeConfig = EntityManager.CreateEntity();
EntityManager.AddComponentData(netcodeConfig, new PredictedPhysicsConfig
{
PhysicsTicksPerSimTick = 1,
DisableWhenNoConnections = true,
});
}
protected override void OnUpdate()
{
}
}
It's probably not the best way but I still expect it to work
mm ok, only difference to me is that it runs in a system and has DisableWhenNoConnections = true instead of false
What I noticed is that if I add a cube to my subscene and give it a dynamic physics body, it will collide with my terrain and bounce, roll around, etc
But if I make my player prefab's physics body dynamic instead of kinematic, it just falls through
Ok fuck me
I put my TerrainChunkMeshGenerationSystem in the ClientAndServerSimulationSystemGroup but I put my TerrainChunkGenerationSystem in the ClientSimulationSystemGroup
So the server didn't generate the terrain, so the player fell through on the server side, so the client received snapshots of the player falling through
And now my raycasts work too
Next-Gen Rendering with Unity. Please sign up now and get a free gift: https://www.indiegogo.com/projects/the-unity-improver-nano-tech
Hey all: do you know if it is possible to iterate only a portion of a TransformAccessArray through a IJobParallelForTransform job?
I have a doubt now, maybe TransformAccessArray is not meant to be cached, but recreated every iteration?
what are you even trying to do?
iterate only a portion of the TransformAccessArray?
like let's say for an example sake I want to set only the first 100 positions in the array
and not to be forced to iterate it all
but I have the impression I may have misunderstood how to use it, if I should create the TransformAccess every iteration may make more sense. However it's still awkward if the number of gameobjects change, since the array must be of the exact size
so if I want to reserve space but not using it is a problem
in conclusion: I Wish I could at least pass an array and the count in the TransformAccessArray constructor, but it seems that even that is not possible
Entity shows up in game view
But not in scene view
How
I checked in the hierarchy and the entity exists in both client and server worlds
Not that it only existing in one of them could change something in my opinion but I don't know what to check
Same Translation and LocalToWorld values in both worlds too
I restarted Unity and the issue did not fix itself
But my PredictedPhysicsConfig singleton works now? Despite that I didn't touch the system that creates it?
error NetCode: GhostField missing on field Alter.Characters.PlayerInput.Tick . Buffers or CommandData must have all fields annotated
^ When I first saw this error, I didn't think much and simply added the GhostField attribute to the Tick property of my following ICommandData-implementing struct:
public struct PlayerInput : ICommandData
{
[GhostField]
public uint Tick { get; set; }
[GhostField(Quantization = 1000)]
public float3 Translation;
}
But I just noticed this in Netcode for Entities's source code:
public interface ICommandData : IBufferElementData
{
[DontSerializeForCommand]
uint Tick { get; set; }
}
Should I replace the GhostField attribute on PlayerInput.Tick with DontSerializeForCommand?
Wait no I can't
If I do then I still get the same compiler error
It really wants me to use annotate all PlayerInput fields with GhostField
Looks like you are correct, all fields should be ghost fields and it should be marked as ghost component
I have an Entity Command Buffer question...
Say I have some entity that I delete with an ECB early in the loop.
There is no guarantee that, some later system that runs before the ECB plays back, reading that entity before it is destroyed, to do some logic, right?
correct
Unity when 0.51? XD
hopefully, before we all die out of old age
So does dots have animations yet?
Nope, not before long after 1.0
Have to rely on an hybrid with mecanim or roll your own animation implementation for DOTS
or find someone that sleeps less than you and already implemented it
I couldn't even find someone to pay to make that for me 9 months ago
Keep an eye on user DreamingImLatios 's framework, it will include animation at some point
Look at "Kinemation" here https://github.com/Dreaming381/Latios-Framework
Oh actually he did speed up this package I guess, looks like he published it in a public alpha stage https://forum.unity.com/threads/0-4-5-my-personal-dots-framework-latios-framework.797685/page-3#post-8077046
Actually it makes sense to annotate the Tick property with GhostField: you want the peer to know which tick the command is from in an authoritarian server model
I don't know why it's annotated with DontSerializeForCommand in the definition of ICommandData
Also there is this vertex animation dots project: https://github.com/maxartz15/VertexAnimation
Tens of thousands of animated 3d models. Just not the fancy rigs of the normal animation package.
public class GhostComponentAttribute : Attribute
{
// ...
/// <summary>
/// Gets or sets the type of ghost this component should be sent to if the ghost is owner predicted.
/// </summary>
public GhostSendType OwnerPredictedSendType {get; set;}
I don't want player input to be sent back from the server to any clients, right? So I should use GhostSendType.None?
Any native collection out there that can insert sorted?
so, uhm, who knows why nativecontainers are so slow in unbursted code? I said the problem is marshalling but some guy tells me I'm wrong. So what is it?
{
var obstacle = Obstacles[i];
var pp1 = new PolarCoords() {angle = 10, radius = 20};
var pp2 = new PolarCoords() {angle = 20, radius = 10};
// PolarHelpers.CartesianToPolar(ObserverPosition, obstacle.position1, out var pp1);
// PolarHelpers.CartesianToPolar(ObserverPosition, obstacle.position2, out var pp2);
ObstacleDatas[i] = new ObstacleData()
{
cp1 = obstacle.position1,
cp2 = obstacle.position2,
direction = obstacle.dir,
pp1 = pp1,
pp2 = pp2,
obstacle = i,
};```
when a thing like that became one of the two bottlenecks I have (other one is sort) I'm thinking i've reached the end of what I can squize out of it performance wise