Search Unity

Prefabs vs DataObjects?

Discussion in 'Getting Started' started by gtg287y, Apr 29, 2015.

  1. gtg287y

    gtg287y

    Joined:
    Apr 29, 2015
    Posts:
    2
    I have a simple game that has several hundred different Tiles that can appear on screen, that vary only in a handful of variables (not in any behavior).

    My Object-Oriented instincts say to have a single PreFab and allow instantiations of it to be changed based on how the underlying DataObject (associated inside a component) was created.

    I'm seeing references that the "best practice" for Unity might instead have each of my hundreds of Tiles be it's own PreFab. Variables are kept in components, and there might not even be a game object.

    Ideally, I'd like to be able to create new types of Tiles very quickly, through a factory somewhere, or an XML importer putting the new DataObjects in a database, or something like that. It seems like making each of my mostly-the-same Tiles a Prefab requires me to do a lot of dragging and dropping and editing, which really slows down my workflow.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Yeah, man. Having them as separate prefabs sounds like a giant pain in the ass. If you have the ability to set them with variables/components in code, then by all means do that.

    No matter what people may say as "best practice", if it helps make things easier to maintain and faster for you to produce, it's the correct option.
     
    Kiwasi, Ryiah and BrandyStarbrite like this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Best practice for two or three objects is prefab.

    For a hundred you'll want to serialise the data and load it from a file. No point writing all that out in the inspector. Plus typos will be hard to spot.
     
    zombiegorilla likes this.
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Indeed. You can also store the data in a spreadsheet or something (google docs works well), and then just export them as json/xml/txt whatever. Makes it easy to browse and look over all your data in one place.

    Or if you are like me, and want completely overkill the whole thing, write a complete data/asset management tool in Unity (not editor). It is a great way to completely eliminate any possible time savings that could have been saved. ;)
     
    Last edited: Apr 30, 2015
    Kiwasi and Ryiah like this.
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Just publish it on steam as a mod tool.
     
    Ryiah likes this.