Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Is there any way to work with Entities and Prefabs?

Discussion in 'Project Tiny' started by Diablo404, Dec 9, 2018.

  1. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    I'm working with tilemaps and I'd like to make prefab from level design and instantiating them at will.

    But, if it seems possible to make a prefab from an entity, it seems impossible to instantiate it (even directely from project view to hierarchy). And when clicking on it, I get the error:
    InvalidOperationException: Requesting 'prefabContentsRoot' from Awake and OnEnable are not supported

    Any tips on this?

    ps: Could it be possible to make a sticky thread where we could reference bugs/tips on this new way of handling Unity with Projet Tiny?
     
  2. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    The more appropriate way I found to to this is (working on 2018.3.0b12):
    - Go to Entities Folder in Project Window
    - Right Click -> Create -> Tiny -> EntityGroup
    - Name it as you want, let's say ExamplePrefab
    - Double click it
    - Inside the hierarchy, fill it with gameobjects with properties that you want
    - Save ( Ctrl + S or Cmd + S )
    - Right Click on your entity groupe in Hierarchy -> Unload Entity Group ( not mandatory since it seems that only the main EntityGroup is displayed when you hit the Play button. But prevention is better than cure, so I find it clearer this way. Up to you )
    - On one of your System script:
    Code (CSharp):
    1. let instance = ut.EntityGroup.instantiate(world, 'game.ExamplePrefab')[0];
    And here it is, it should do the trick. I don't know how to manipulate the prefab at this time (position, etc). I might add some informations about it later. If someone is keen to share, that be great too.

    I still think that a sticky thread with every tips and tricks and techniques to do basic stuff that people are used to do inside Unity would be great.
     
  3. silantzis

    silantzis

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    13
    We currently have a very early/experimental version of prefabs in Tiny. You can create one through the context menu of an entity (Right Click -> "Make Prefab"). Once you have a Tiny Prefab asset you can drag it into your hierarchy view to create instances. The prefab asset can be updated through the "Apply" and "Revert" buttons on the entity header OR per field through a context menu.

    NOTE: This workflow is Editor only. At runtime Prefabs are treated as normal EntityGroups

    There is a known issue when dragging an entity into the project window it will create a standard GameObject prefab which is not usable in Tiny. I've create an issue for it here https://fogbugz.unity3d.com/f/cases/1108362/
     
  4. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    Thanks for your answer.

    Okay, I'll try that one too and see if it comes in handy.
     
  5. silantzis

    silantzis

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    13
    To answer your question regarding runtime instantiation and initialization. You can use the world API to read and write component data to the instantiated entities.

    Code (CSharp):
    1. let instance = ut.EntityGroup.instantiate(world, 'game.ExamplePrefab')[0];
    2.  
    3. // Sets the local position of the first entity to 5,5,5
    4. var transform = this.world.getComponentData(instance, ut.Core2D.TransformLocalPosition);
    5. transform.position = new Vector3(5, 5, 5);
    6. this.world.setComponentData(instance, transform);
     
  6. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    Works great!
    Thank you!