Coder Social home page Coder Social logo

unity-technologies / entitycomponentsystemsamples Goto Github PK

View Code? Open in Web Editor NEW
6.8K 849.0 1.5K 484.06 MB

License: Other

C# 97.55% ShaderLab 2.18% HLSL 0.12% HTML 0.15%
burst multicore-processors ecs entity component system jobs csharp tutorials documentation

entitycomponentsystemsamples's Introduction

DOTS Samples

Learning DOTS

For those new to DOTS, here's the recommended sequence to follow through the introductory material in the Entities samples project:

A few short videos introduce the basic concepts of the job system and ECS:

  1. Video: The C# Job system (11 minutes)
  2. Video: ECS Entities and components (10 minutes)
  3. Video: ECS Systems (7 minutes)
  4. Video: ECS Baking (6 minutes)

You may also want to read the Entities API overview, which is briefer and more sequentially structured than the manual.

These starter samples each have an explanatory video:

Beyond the above starter samples, there are samples covering Baking, Streaming (for large worlds and scene management), and Miscellaneous.

For quick reference of basic API usage, use these example code snippets and cheat sheets:

Finally, there's the ECS Network Racing sample, which is a working DOTS game using DOTS Netcode and Physics.

Release notes

This is the samples release for Unity 2022.3 LTS and the 1.0 release of the Entities, Netcode, Physics, and Entities.Graphics packages.

entitycomponentsystemsamples's People

Contributors

abdul-unity avatar brianwill avatar brianwill-unity avatar cinight avatar cookiesalad avatar drealmer avatar fabriziounity avatar henrikpoulsen avatar itr13 avatar josepmariapujol-unity avatar julianunity avatar kjellander-unity avatar mahmoudbagherimoghaddam avatar martingram avatar roberto-renzetti-unity avatar seanp-unity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

entitycomponentsystemsamples's Issues

Editor Crashes when adding Rotation Component

Editor Version:

  • 2018.3.0b6 (2018.3.0.44795)

ECS Version:

  • 0.0.12.preview.19

Steps:

  1. Create Empty
  2. Select the Empty
  3. Click the Add Component Button
  4. Search and select the Rotation Component

Result:

  • After approx. 3 seconds, the Editor will crash.

Example features modifying a foreach iteration variable, which raises an error.

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/Documentation/content/getting_started.md#componentsystem---a-step-into-a-new-era

Here the code shows this:

    foreach (var e in GetEntities<Group>())
    {
        e.Transform.rotation *= Quaternion.AngleAxis(e.Rotator.Speed * deltaTime, Vector3.up);
    }

But doing this raises this error: Cannot modify members of 'e' because it is a 'foreach iteration variable'.

Error about package manager version

In manifest.json:
"com.unity.package-manager-ui": "2.0.0-preview.3"
will occur an error when open the project in samples
If I change this to 1.9.11, it will be OK.

How you test system from ECS?

1. Question
There is a easy way to test single system?
I write UnityTest and run them with TestRunner but they look more like integration tests than unit tests and almost always is hard to assert result for them.

2. Request
Could you add unit tests to yours samples?
It would be grate if i could pass to system prepared entity, call update function and check changes on entity.

3. Missing
You have paragraph in your vision "Our code comes with full unit test coverage" but you missing "Our feature is easy unit testable".

Sorry wrong post

Hi, I was able to fetch the list of discovered devices using notification once app is started. But, if tried again to fetch the list of devices the list is empty. But, once app is restarted I can find device again, I believe it has to do something with discovered notification. I am new to objective c. How can I correct device discovery in objective c. Thanks

README.md Installation Guide doesn't work

Needed to "check" preview packages before you can see "Entities".

After installing Entities Unity crashes and will continue to crash until you remove the new package from the manifest.json

4.x was already selected.

I tried installing various packages that might be dependencies, but it's still crashing.

jobs, collections, mathematics, boost, ...

Question about EntityManagerExtensions - Instantiate with GO

Hey all!

The code in question is:

unsafe public static Entity Instantiate(this EntityManager entityManager, GameObject srcGameObject)
        {
            if (entityManager.m_CachedComponentList == null)
                entityManager.m_CachedComponentList = new List<ComponentDataWrapperBase>();

            var components = (List<ComponentDataWrapperBase>)entityManager.m_CachedComponentList;
            srcGameObject.GetComponents(components);
            var count = components.Count;
            ComponentType* componentTypes = stackalloc ComponentType[count];

            for (var t = 0; t != count; ++t)
                componentTypes[t] = components[t].GetComponentType();

            var srcEntity = entityManager.CreateEntity(entityManager.CreateArchetype(componentTypes, count));
            for (var t = 0; t != count; ++t)
                components[t].UpdateComponentData(entityManager, srcEntity);

            return srcEntity;
        }

What is the usage of m_CachedComponentList? I'm not able to see any working caching mechanisms. No early out.
Does srcGameObject.GetComponents has an internal logic for resolving the components?
If so, how does this cache work with multiple different gameobjects?

As the need still persists to instantiate multiple gameobjects in a single frame like UILabels or something I'm still falling back to pools, which Joachim mentioned should not be needed anymore.

I also scrubbed the documentation but found no answer or statement how fast this should be or the state of hybrid pooling.

BurstCompile

hi, when should i add BurstCompile attrubute?
like this:
[BurstCompile]
struct CalculatePositionsJob : IJobParallelFor
{
}

[email protected] 'StringBuffer' does not exist in the current context

I found an error when install Unity Entities version 0.0.12-preview.8. The Unity Console said:

/Users/wingyplus/Library/Unity/cache/packages/packages.unity.com/[email protected]/Unity.Entities.Properties/JsonVisitor.cs(222,13): error CS0103: The name 'StringBuffer' does not exist in the current context

The package that I install on project is:

{
  "dependencies": {
    "com.unity.ads": "2.0.8",
    "com.unity.analytics": "2.0.16",
    "com.unity.entities": "0.0.12-preview.8",
    "com.unity.incrementalcompiler": "0.0.42-preview.16",
    "com.unity.package-manager-ui": "1.9.11",
    "com.unity.purchasing": "2.0.3",
    "com.unity.textmeshpro": "1.2.4",
    "com.unity.modules.ai": "1.0.0",
    "com.unity.modules.animation": "1.0.0",
    "com.unity.modules.assetbundle": "1.0.0",
    "com.unity.modules.audio": "1.0.0",
    "com.unity.modules.cloth": "1.0.0",
    "com.unity.modules.director": "1.0.0",
    "com.unity.modules.imageconversion": "1.0.0",
    "com.unity.modules.imgui": "1.0.0",
    "com.unity.modules.jsonserialize": "1.0.0",
    "com.unity.modules.particlesystem": "1.0.0",
    "com.unity.modules.physics": "1.0.0",
    "com.unity.modules.physics2d": "1.0.0",
    "com.unity.modules.screencapture": "1.0.0",
    "com.unity.modules.terrain": "1.0.0",
    "com.unity.modules.terrainphysics": "1.0.0",
    "com.unity.modules.tilemap": "1.0.0",
    "com.unity.modules.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",
    "com.unity.modules.umbra": "1.0.0",
    "com.unity.modules.unityanalytics": "1.0.0",
    "com.unity.modules.unitywebrequest": "1.0.0",
    "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    "com.unity.modules.unitywebrequestaudio": "1.0.0",
    "com.unity.modules.unitywebrequesttexture": "1.0.0",
    "com.unity.modules.unitywebrequestwww": "1.0.0",
    "com.unity.modules.vehicles": "1.0.0",
    "com.unity.modules.video": "1.0.0",
    "com.unity.modules.vr": "1.0.0",
    "com.unity.modules.wind": "1.0.0",
    "com.unity.modules.xr": "1.0.0"
  }
}

Run on Unity version 2018.2.2f1
Script Runtime Version: .NET 4.x Equivalent
Script Backend: IL2CPP
Api Compatibility Level: .NET standard 2.0

Entities 0.0.12-preview.5 C# 6.0 Error

After updating ECS to preview 5 I've got this error: "[email protected]/Unity.Entities/SerializeUtility.cs(28,73): error CS1644: Feature `out variable declaration' cannot be used because it is not part of the C# 6.0 language specification" .

Editor: 2018.1.0f2
Scripting Runtime: .NET 4.x
Scripting Backend: Mono
Api Compatibility: .NET 4.x

Update: Opening and closing the Editor seems to fix it

PlayerInput IComponentData contains logic

PlayerInput contains logic.

IComponentData should only contain data. Taken from your docs

... the name refers directly to the fact that [IComponentData] only stores data

A computed getter like bool Fire is logic and also not serializable. Shouldn't this code be in a system?

Doesn't support ISharedComponentData inject now?

This is my code. After create a entity with SpawnRandomSharedData and SpawnData, the update function of RandSpawnSystem does not be Called

public class RandSpawnS : ComponentSystem
{
struct Group
{
public int Length;
public EntityArray Entities;
public ComponentDataArray<SpawnData> SpawnDatas;
[ReadOnly] public SharedComponentDataArray<SpawnRandomSharedData> SpawnRandomSharedDatas;
}
[Inject] private Group m_data;
protected override void OnUpdate()
{
Debug.Log("RandSpawnS.OnUpdate");
}
}

Broken Links in cheatsheet.md

The links for NativeList and NativeQueue in EntityComponentSystemSamples / Documentation / content / cheatsheet.md are broken. They go to a 404 page. I suggest checking all of the links on that page because I doubt they are the only ones.

Unable to instantiate prefab. Prefab may be broken. GravityDemo 2018.1.6f1

Hi,

For the SpaceSim Scene, I am getting the following hierarchy:
Missing Prefab
Missing Prefab
Main Camera
Settings

I tried to import the Asteroid and Star Prefab but I am getting this error.

Complete Error:
Unable to instantiate prefab. Prefab may be broken.
UnityEditorInternal.InternalEditorUtility:HierarchyWindowDrag(HierarchyProperty, Boolean, HierarchyDropMode)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Missing file error

Hi folks

Seems I'm getting
Assembly has reference to non-existent assembly 'Unity.Postprocessing.Runtime'

Error over and over. What download is this in? I've just installed
"ScriptableRenterPipeline-Master"

Thanks!

ComponentDataWrapper is deprecated?

I got this error today

The type or namespace name 'ComponentDataWrapper<>' could not be found (are you missing a using directive or an assembly reference?)

And it seem like I can't find reference about ComponentDataWrapper<> in this repo anymore. Is it deprecated or something?

Should provide a way to reduce the number of threads

As a developer using Unity (both for plugins and games), I have done a lot of multithreading in my projects already (I'm not using Unity API in my threads as it's forbidden, but still, I need threads for others heavy and long running computations).
Problem is the job system takes all available CPU cores and my own classical threads may create contention.

I think I'm not the only one in this situation. It would be great if we could reduce the number of threads taken by the Job system, or even better, get access to the thread pool of the job system in order to pick up some thread for classical multithreading.

Installation Guide - Getting Started Missing

Even if Unity abandons this repository, it is still found easily and thus should still either contain or reference current "Getting Started" documentation.

For example, as of 4/18/2018 only the 2018.1.b12 beta works, not 2018.1.b13, which is confusing and not documented here.

There are some Unity forum posts, but that content should be here as well, or at least explicitly referenced and explained.

Entire project is not working on 2018.1.0b11.

Newest beta version of editor is 2018.1.0b11, but I've got an error below.

Assembly has reference to non-existent assembly 'Unity.Burst'

Probably I need to get "2018.1.0b12" editor but where can i find it?

Unable to access SharedComponentDataArray in JobProcessComponentData/JobParallelFor

Hello,
I encountered what the title describes recently.
On the one hand, SharedComponent cannot be in the type parameters of JobProcessComponentData.
On the other hand, if I pass a SharedComponentDataArray to a ParallelFor job, Burst complains about getting SharedComponent from List. It seems that this relates to EntityManager.GetAllUniqueSharedComponentData who accept List as a out parameter.
So is this intended? I just can't access SharedComponent in jobs, must iterate over all unique ones and schedule jobs per SharedComponent? Or did I miss some content in the doc?
Thanks and please pardon my English.

Enum in ComponentDataWrapper don't get set on ComponentData

I tried something like that:

public enum FactionType
{
	Friendly,
    Enemy
}

[Serializable]
public struct Faction : IComponentData
{
	public FactionType Value;
}

public class FactionComponent : ComponentDataWrapper<Faction>
{
}

But changing the Value on the FactionComponent doesn't change it on the Entity ComponentData.
I though I was doing something wrong...

I checked the "MeshInstanceRendererComponent" which has a ShadowType enum, and same behaviour...
You can set the ShadowType to anything at the end it will still be Off

Why does PlayerData have a Length ?

Why does PlayerData have a Length? Why not check PlayerData.Input.Length? How is this hydrated?

// SEE THIS LINE

public class PlayerInputSystem : ComponentSystem
    {
        struct PlayerData
        {            
            // SEE THIS LINE
            public int Length;

            public ComponentDataArray<PlayerInput> Input;
        }

        [Inject] private PlayerData m_Players;

        protected override void OnUpdate()
        {
            float dt = Time.deltaTime;
            
            // SEE THIS LINE
            for (int i = 0; i < m_Players.Length; ++i)
            {
                UpdatePlayerInput(i, dt);
            }
        }

        private void UpdatePlayerInput(int i, float dt)
        {
            PlayerInput pi;

            pi.Move.x = Input.GetAxis("Horizontal");
            pi.Move.y = Input.GetAxis("Vertical");
            pi.Shoot.x = Input.GetAxis("ShootX");
            pi.Shoot.y = Input.GetAxis("ShootY");

            // SEE THIS LINE
            pi.FireCooldown = Mathf.Max(0.0f, m_Players.Input[i].FireCooldown - dt);

            // SEE THIS LINE
            m_Players.Input[i] = pi;
        }
    }

Bad performance of EndFrameTransformSystem

I am using Unity 2018.2.9f1 for testing, and no changing for the example.

In the TwoStickPure scene, I just let my jet skip the missiles. Bad performance caused by the ComponentChunkIterator:GatherChunksJob in EndFrameTransformSystem .

How to fix this?
c

linux - libncurses.so.5 not found - System.EntryPointNotFoundException: mono_dllmap_insert

i get these errors when trying to load the packages
"com.unity.incrementalcompiler": "0.0.38",
"com.unity.entities": "0.0.12-preview.1":

System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'ZeroMQ.lib.zmq' threw an exception. ---> System.EntryPointNotFoundException: mono_dllmap_insert

DllNotFoundException: Unable to load the unmanaged library `/home/david/.config/unity3d/cache/packages/staging-packages.unity.com/[email protected]/.Runtime/libburst-llvm.so` Reason: libncurses.so.5: cannot open shared object file: No such file or directory

Unexpected error while trying to initialize the burst JIT compiler: Unexpected exception occured while initializing burst JitCompilerService

tested on arch linux with Unity Editor 2018.1.0f2

cheatsheet, add one line to explain each type

we don't need namespace of type because these are automatically solved by Rider & VS
what would help is this:
| EntityArchetype | unique array of ComponentType, used to group entities

I have no access to the samples

So thats all, i dont know if you have remove the source samples or im not allowed to see them.
anyway would be great to get access to them in order to learn.

Pd Sorry for my english and thanks!

Cannot open 'Pure' sample project, Unity hangs

OS: Windows 10

Unity Versions: 2018.1.0f2, 2018.1.1f1, 2018.1.6f1, 2018.2.0b10

Reproduction:

  • On a fresh checkout of this repository open TwinStickShooter/Pure in Unity

Symptoms:

  • Unity hangs at 'Compiling Assembly Definition Files scripts':
    image
  • Last significant line in %LOCALAPPDATA%/Unity/Editor/Editor.log is always Cannot transition thread 00002D10 from ASYNC_SUSPEND_REQUESTED with ASYNC_SUSPEND_REQUESTED.
  • Editor.log from an attempt with Unity 2018.1.0f2

Things I've tried:

  • Using the latest incremental compiler 0.0.42-preview.9
  • Using an older version of the incremental compiler 0.0.29

Why is it better to copy ComponentDataArray to a NativeArray?

var boards = new NativeArray<Board>(BoardGroup.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var boardPositions = new NativeArray<Position>(BoardGroup.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var boardEntities = new NativeArray<Entity>(BoardGroup.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
for (int i = 0; i < BoardGroup.Length; i++)
{
boards[i] = BoardGroup.Boards[i];
boardPositions[i] = BoardGroup.Positions[i];
boardEntities[i] = BoardGroup.Entities[i];
}
for (int i = 0; i < BoardGroup.Length; i++)
{
var board = boards[i];
var boardPosition = boardPositions[i];
var boardEntity = boardEntities[i];

I'd iterate on the ComponentDataArray directly. What's the benefit from it?

Unity shuts down when I try to open the project

I cloned the repository and try to open the Samples folder in Unity, but it crashes. I've tried it with Unity 2018.10.2f1 and also Unity 2018.2.3f1 (which I think is the last version used in the repository).

When I delete the packages manifest I'm able to open the project, but it doesn't compile.

When I use the manifest provided in the repo the project crashes and I'm unable to open it again.

I've tried to download the packages directly in the Packages Window but it doesn't work either.

Unity packages error

C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/[email protected]/Editor/BurstReflection.cs(19,67): error CS0246: The type or namespace name `AssembliesType' could not be found. Are you missing an assembly reference?

C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/[email protected]/Editor/BurstReflection.cs(155,73): error CS0246: The type or namespace name `AssembliesType' could not be found. Are you missing an assembly reference?

C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/[email protected]/Unity.Collections/NativeHashMap.cs(602,14): error CS0246: The type or namespace name `NativeSetThreadIndex' could not be found. Are you missing an assembly reference?

C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/[email protected]/Unity.Collections/NativeHashMap.cs(794,14): error CS0246: The type or namespace name `NativeSetThreadIndex' could not be found. Are you missing an assembly reference?

C:/ProgramData/Unity/cache/packages/staging-packages.unity.com/[email protected]/Unity.Collections/NativeQueue.cs(323,8): error CS0246: The type or namespace name `NativeSetThreadIndex' could not be found. Are you missing an assembly reference?

When I open this samples project in Unity2018.1.0b13, editor give me five error.

Dot Net Standard Support

A college has told me that there is a DotNetStandard version of the Unity dlls. He was able to find these dlls in a roundabout way by building the project with 4.6 support. Is there a place where I can find these dlls?

Moreover, does ECS, and specifically Unity.Collections.NativeArray support running on DotNetStandard ? Would like to include these new data structures in a common / dto library.

Suggestion : Archetype interface / struct

// Same API but slightly more efficient
EntityArchetype archetype = EntityManager.CreateArchetype(ComponentType.Create<MyComponentData>(), ComponentType.Create<MySharedComponent>());

This method to create archetypes is going to get messy very fast.
I can see a list of a dozen typeof`s in the code, yuck.
May I suggest defining archetypes on a struct?

struct BetterArcheType : IEntityArchetype
{
   public MyComponentData;
   public MySharedComponent;
   public MyOtherComponenet;
}

EntityArchetype archetype = EntityManager.CreateArchetype<BetterArcheType>();

I feel this would be 1) easier to read. 2) Follows the same conventions as the rest of the system. 3) more familiar to us in OOP land.

My only fear is that this might use reflection to identify the parts, but this is happening on bootstrap and can be automated using a weaver technology easy enough, so whatever.

ECS ComponentSystem OnUpdate() is not getting called on Android.

ECS preview 8

I have a project that is pure ECS based. Everything works fine with debug logs in the editor for Android, but none of the ComponentSystem.OnUpdate() is getting called while I run it on my cellphone.

I've checked ScriptBehaviourManager.Update() and ScriptBehaviourManager.Update() but they were not getting called either. Monobehaviors Update() method works fine.

I'm making a RTS game prototype where I disabled the default world and automatic bootstrap, but I don't have any hybrid injections going on. Everything except for the main camera is ECS based.

Any advice will be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.