Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 LaphicetCrowe · Jan 20, 2021 at 09:55 PM · dotsobject referenceobject pool

Object pool with DOTS?

So I'm a nerd for optimisations and I've been looking into Unity's new DOTS/ECS and I can certainly appreciate the boons it gives game developers. However, while I was able to implement a 3D pathfinding algorithm with it, I'm finding an object pool implementation to be a bit more complicated. While I can use NativeArray and/or NativeList, the complication comes when specifying a prefab, as the prefab is a GameObject reference and as far as I know, DOTS structs having any reference variables is a big no-no. That, or I can't find anything akin to a weak ref container type. Any help would be appreciated, thanks!

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
2
Best Answer

Answer by andrew-lukasik · Jan 21, 2021 at 12:01 AM

Start with familiarizing yourself with GameObject to Entity conversion workflow first. You may find out that's instantiating from Entity prefabs is good enough:

 using System.Collections.Generic;
 using UnityEngine;
 using Unity.Mathematics;
 using Unity.Entities;
 using Unity.Transforms;
 
 public class HybridSpawner : MonoBehaviour
 {
 
     Dictionary<GameObject,Entity> _prefabs = new Dictionary<GameObject,Entity>( capacity:100 );
 
     World _world;
     EntityManager _entityManager;
     BlobAssetStore _blobAssetStore;
     GameObjectConversionSettings _conversionSettings;
 
     void Start ()
     {
         _world = World.DefaultGameObjectInjectionWorld;
         _entityManager = _world.EntityManager;
         _blobAssetStore = new BlobAssetStore();
         _conversionSettings = GameObjectConversionSettings.FromWorld( _world , _blobAssetStore );
     }
 
     void OnDestroy ()
     {
         _blobAssetStore.Dispose();
     }
 
     public void Spawn ( GameObject prefab , Vector3 position , Quaternion rotation )
     {
         Entity entityPrefab = ToEntityPrefab( prefab );
         Entity instance = _entityManager.Instantiate( entityPrefab );
         _entityManager.SetComponentData( instance , new Translation{ Value = position } );
         _entityManager.SetComponentData( instance , new Rotation{ Value = rotation } );
     }
 
     public void Warmup ( GameObject prefab ) => ToEntityPrefab( prefab );
 
     Entity ToEntityPrefab ( GameObject prefab )
     {
         Entity entityPrefab;
         if( !_prefabs.TryGetValue( prefab , out entityPrefab ) )
         {
             entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy( prefab , _conversionSettings );
             _prefabs.Add( prefab , entityPrefab );
         }
         return entityPrefab;
     }
 
 }
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 LaphicetCrowe · Jan 21, 2021 at 12:32 AM 0
Share

Wow... I had to read that several times to sorta understand it.

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

157 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

Related Questions

Get GameObject dependencies only once for JobComponentSystem 1 Answer

Can the burst compiler be used for any code? 0 Answers

Does DOTS have a animation component? 1 Answer

Someone Please provide reference materials for starting with Unity Dots 1 Answer

I'm not seeing a performance increase with the Job System. Help 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