• 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 /
  • Help Room /
avatar image
1
Question by ProfessionalNobody · May 27, 2020 at 08:56 AM · scriptableobjectdots

"RuntimeSets" in DOTS

Hey folks,


So, I watched this talk: Unite Austin 2017 - Game Architecture with Scriptable Objects


I really like the idea behind Runtime sets (~41:14 in the video), but can't quite figure out how to make it work with DOTS. I am still busy trying to wrap my head around DOTS, so maybe I am just missing something obvious. Here is what I tried, first me experimenting with DOTS and then me trying to integrate "RuntimeSets" into it.


If this is not possible (now). I would be open to any alternative that accomplishes the following;

  • Allows me to get away from the Singleton pattern for managing lists / data.

  • Allows me to populate the list via both the editor and code

  • The data is accessible from within a DOTS System.

  • (Optional) The data is still in a struct (for DOTS)


DOTS:

 using Unity.Entities;
 
 [GenerateAuthoringComponent]
 public struct Skill : IComponentData
 {
     public int id;
     public int level;
     public float progress;
     public float incrementer;
 }



 using Unity.Entities;
 using Unity.Mathematics;
 
 public class TestSystem : SystemBase
 {
     protected override void OnUpdate()
     {
         float delta = Time.DeltaTime;
 
         // TEMP
         TestManager testManager = TestManager.instance;
 
         Entities.ForEach((ref Skill skill) =>
         {
             skill.progress = skill.progress + (skill.incrementer * delta);
 
             if (skill.progress >= 100.0f) {
                 skill.level++;
                 skill.progress = 0.0f;
             }
 
             testManager.skills[skill.id].text = "Skill" + skill.id + ": " + skill.level + " | " + math.round(skill.progress * 100.0f) / 100.0f;
         }).Schedule();
     }
 }
 


DOTS with "RuntimeSets":

 // ----------------------------------------------------------------------------
 // Unite 2017 - Game Architecture with Scriptable Objects
 // 
 // Author: Ryan Hipple
 // Date:   10/04/17
 // ----------------------------------------------------------------------------
 
 using System.Collections.Generic;
 using UnityEngine;
 
 public abstract class RuntimeSet<T> : ScriptableObject
 {
     public List<T> Items = new List<T>();
 
     public void Add(T thing)
     {
         if (!Items.Contains(thing))
             Items.Add(thing);
     }
 
     public void Remove(T thing)
     {
         if (Items.Contains(thing))
             Items.Remove(thing);
     }
 }
 
 [CreateAssetMenu]
 public class SkillRuntimeSet : RuntimeSet<SkillMono>
 { }
 



 using UnityEngine;
 
 public class SkillMono : MonoBehaviour
 {
     public SkillRuntimeSet RuntimeSet;
     public Skill SkillData;
 
     private void OnEnable()
     {
         RuntimeSet.Add(this);
     }
 
     private void OnDisable()
     {
         RuntimeSet.Remove(this);
     } 
 }

 using Unity.Entities;
 
 public class TestSystem : SystemBase
 {
     protected override void OnUpdate()
     {
         float delta = Time.DeltaTime;
 
         // Knew this wouldn't work on Classes, but had to try anyway.
         // Trying to grab the struct (Skill) directly doesn't work, either.
         Entities.ForEach((ref SkillMono skillMono) =>
         {
             var skill = skillMono.SkillData;
             skill.progress = skill.progress + (skill.incrementer * delta);
 
             if (skill.progress >= 100.0f) {
                 skill.level++;
                 skill.progress = 0.0f;
             }
 
         }).WithoutBurst().Run();
     }
 }



This post is already pretty long because of the code snippets, but it would be great if anyone knows how to do the Events from that same talk (~33:44) from within a DOTS system and could share.
Also, I realize DOTS isn't ready yet, but I still want to start understanding it and make some use of it.

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
0

Answer by andrew-lukasik · May 28, 2020 at 09:16 PM

I think this pattern may be obsolete for DOTS.

Main reason being that entities and components are stored and easily accessible as arrays already. And to access those arrays you don't even need any asset references but just components/tags you're after at the moment.

You can inspect those collections of entities in Entity Debugger window. You cannot edit them there yet, but for that you can write your own custom editor window where entities can be spawned/destroyed manually etc.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

207 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 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

How do I decide which Conversation to start when clicking on an NPC? 0 Answers

ScriptableObject not Serializing? 0 Answers

Can't you add tags using a script instead of tagging it through the editor ? 1 Answer

Keep data created at runtime in ScriptableObjects? 1 Answer

Need help designing a dialogue system (or, how could I deal with referencing scene objects in ScriptableObjects?) 0 Answers


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