Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by bakos13 · May 20 at 06:27 PM · dotsinput.getkey

Using SystemBase (ECS/DOTS) but code will not execute at all!

Hello there,


I apologize ahead of time if the solution to my problem is so simple I should have seen it earlier - for some reason though, I cannot (for the life of me) seem to get my SystemBase scripts to execute/register ANY code/input!


For example:

I follow this video to start using prefabs: https://www.youtube.com/watch?v=m9YAxRhCZ8M&t=459s&ab_channel=TurboMakesGames


But got stuck at Input.GetKeyDown(KeyCode.A) - as mine did not want to register/execute! I tried changing a few things to just get my code to debug a log at least, but still nothing~


I'm at a loss - if anyone is able to assist me it would be greatly appreciated!

Sincerely,

Bakos13


PS. I googled my issue but it seems no one else is having it! aha.. so.. Where did I go wrong! I know I installed all the required ECS packages as instructed in the video.

  • com.unity.rendering.hybrid (which installs all pre-requisites for entities, mathematics, etc)

  • com.unity.physics

  • com.unity.netcode


My SystemBase script for spawning entities via prefab:


 using Unity.Entities;
 using Unity.Mathematics;
 using Unity.Transforms;
 using UnityEngine;
 using Random = Unity.Mathematics.Random;
 
 [UpdateBefore(typeof(TransformSystemGroup))]
 public partial class gameController : SystemBase
 {
     private Entity _playablePrefab;
     private Entity _capsuleSpawner;
     private Random _random;
     private float3 _minPos = float3.zero;
     private float3 _maxPos = new float3(50, 0, 50);
     private BeginSimulationEntityCommandBufferSystem _ecbSystem;
 
     protected override void OnStartRunning()
     {
         Application.targetFrameRate = 30;
         _playablePrefab = GetSingleton<Playable>().Value;
 
         _random.InitState(4554);
         _ecbSystem = World.GetOrCreateSystem<BeginSimulationEntityCommandBufferSystem>();
 
         _capsuleSpawner = GetSingletonEntity<LastSpawnedPlayable>();
         Debug.Log("1");
     }
 
     protected override void OnUpdate()
     {
         if (Input.GetKey(KeyCode.A))
         {
             Debug.Log("A");
             var newPlayable = EntityManager.Instantiate(_playablePrefab);
 
             SetSingleton(new LastSpawnedPlayable { Value = newPlayable });
 
             var randPos = _random.NextFloat3(_minPos, _maxPos);
             var newPos = new Translation { Value = randPos };
             EntityManager.SetComponentData(newPlayable, newPos);
             Debug.Break();
         }
 
         if (Input.GetKeyDown(KeyCode.S))
         {
             var ecb = _ecbSystem.CreateCommandBuffer();
 
             var newCapsule = ecb.Instantiate(_playablePrefab);
             var randPos = _random.NextFloat3(_minPos, _maxPos);
             var newPos = new Translation { Value = randPos };
             ecb.SetComponent(newCapsule, newPos);
         }
 
         var lastSpawned = GetSingleton<LastSpawnedPlayable>().Value;
         if (lastSpawned != Entity.Null)
         {
             var lastPos = GetComponent<Translation>(lastSpawned);
             var upPos = new float3(25, 25, 25);
             Debug.DrawLine(lastPos.Value, upPos, Color.red);
         }
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by andrew-lukasik · May 22 at 08:11 PM


What you just discovered is that OnUpdate is not always called. Seems surprising but this is a good thing; a feature, not a bug.


  • Let me explain:

Every system does something to very specific set of components ( a.k.a. query), right?

So... since this set of components is known ahead of time - the ecs engine will only call OnUpdate for systems for which entities with a matching set of components exist (!)


The problem in your case is that you didn't realize that query was automagically deduced from the code you wrote. Long story short: ecs figured out that your system does something either to Playable or lastSpawnedPlayable components, so there is no point in updating this system without them present in the World first (system is asleep until one of them appears).


Always look into Systems window. it displays this information here:

SystemBase query


  • TL;DR: adding [AlwaysUpdateSystem] attribute to your system will ignore query requirements for system updates.



screenshot-2022-05-22-215028.png (17.9 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bakos13 · May 22 at 11:16 PM 0
Share

Thank you so much Andrew! You just - quite literally - blew my mind with that response!

This ECS system is VERY intimidating at first!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

137 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

making obgect invisble then visible 1 Answer

How to get constant rotation from tapping a button 1 Answer

Double key combination problem 2 Answers

Bad performance using entity component system 0 Answers

How can I pass data from one job to to the next? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges