Prefabs

112 views
Skip to first unread message

Сергей Наврожин

unread,
Nov 22, 2013, 6:07:54 AM11/22/13
to ash-fr...@googlegroups.com
Hi!

How to make Prefabs in Unity style with Ash?
To be able to quickly update the whole game with new values (if they are not changed in instances in stored 'levels').
The problem with 'default values' is there even with Factory approach, even though i don't like it, given the fact that ECS allows for more data-driven approach, e.g. storing Prefabs in data files.

It is either a matter of serializer/de-serializer. Either a matter of different approach of building and handling entities withing the framework.

Please share your vision Richard, i can't really build any game using your slim and robust framework until i'm solving this one.

Thanx.

Сергей Наврожин

unread,
Nov 22, 2013, 6:46:52 AM11/22/13
to ash-fr...@googlegroups.com
I will try to change serializer side, so it tracks which values are different from prefabs values and saves only that data. Same approach could be used to highlight such data in editor views. If it will work out i'll close the topic :)

James Wrightson

unread,
Nov 23, 2013, 10:45:27 AM11/23/13
to ash-fr...@googlegroups.com
I don't understand the question :(

Do you mean changing a single entity, to update many others - as if they were the same instance?

Rob Bateman

unread,
Dec 9, 2013, 5:40:10 AM12/9/13
to ash-fr...@googlegroups.com, James Wrightson
I think I may have an example of working in this kind of way with Ash. Check out a project i did a while back that uses the approach you are describing:



I use a series of “Archetype” classes that fulfil the same role as the thing you describe as Prefabs. this contains the data for creating a type of Entity, and the EntityManager class handles the creation and destruction of entities derived using these archetypes

Its not quite what Unity does, but it holds many of the same properties as a truly data-driven way of working with game entities


hth!


Rob



-- 
Rob Bateman
Sent with Airmail

On 23 November 2013 at 17:45:29, James Wrightson (guerril...@gmail.com) wrote:

I don't understand the question :(

Do you mean changing a single entity, to update many others - as if they were the same instance?
--
You received this message because you are subscribed to the Google Groups "Ash Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ash-framewor...@googlegroups.com.
Visit this group at http://groups.google.com/group/ash-framework.
For more options, visit https://groups.google.com/groups/opt_out.

Сергей Наврожин

unread,
Jan 3, 2014, 2:24:47 AM1/3/14
to ash-fr...@googlegroups.com, James Wrightson
Hi James,

Well, Unity uses Prefabs instead of factories, as far as i know, because it's a data-driven approach, which Ash promotes (isn't it?), a rational thing to do especially with editor (which uses itself to add prefabs as well). 

So, yes, i managed to make Prefabs, Prefab is basically an entity with number of components with preinited data. Which makes them useful for pooling as well.
In short, there's an xml that stores Prefabs, like that:

<prefab>
<component cclass="ottomoto.components::Prefab" name="bg" precache="2"/>
    <component cclass="ottomoto.components::Transform" x="320" y="200" rotation="0" scale_x="1" scale_y="1" />
    <component cclass="ottomoto.components::SpriteRenderer" visible="true" drawable="{asset:'bg1'}" layer="0"/>
  </prefab>

And there's a level description wich may look like that

<level>
  <entity>
    <component cclass="ottomoto.components::Prefab" name="bg"/>
  </entity>
</level>

Deserializer takes that data, checks that it's based on Prefab, then creates prefab, or in fact takes it from the pool,
then it goes through properties described in the level and sets mentioned vars (in this case, no vars).

If we have something like that for example:

<entity>
    <component cclass="ottomoto.components::Prefab" name="saw2"/>
    <component cclass="ottomoto.components::Transform" y="271" x="252"/>
  </entity>

it means that we have a 'custom' values for Transform component (x, y), and all other components and properties are taken from Prefab.

In Unity, being in Editor, we will see such 'custom' values in Bold if i'm not mistaken.
And yes, it is achievable, one just have to perform per-component per-variable check and compare the values with values stored in Prefabs.
I did manage to do that, so yeah, the Editor looks somewhat like Unity now. Having 'custom' thing highlighted is very useful.
And of course, the main feature is to be able to drop components onto new entity and save everything you did as a Prefab, to be able to use it in the future.
And to be able to have it in the 'Library', which is used for rapid development (drag and drop).

One last thing with Prefabs, as soon as one of the components removed, or added, it's not a Prefab anymore (but of course may be saved as one if it is needed).

Basically, to be able to use Prefabs, one must be able to save only the data which is different from the Prefab entity to the level file, that's all.

Topic is closed.

Cheers.
Reply all
Reply to author
Forward
0 new messages