Jump to content
  • Advertisement
  • entries
    21
  • comments
    20
  • views
    1739

Ode to Nested Prefabs from a noob indie dev

Sign in to follow this  
FatPugStudio

944 views

Prefab.pngHis Majesty, the Prefab

I must admit that i’ve been a bit what you could call ‘lazy’ for the past few months.  Why is lazy hyphenated? Well, because i’m not really lazy, i just tried to finish a game from 0 knowledge of Unity in under two years, which is not an easy task. I spent a lot of sleepless nights working, had a few burnouts, but one thing ultimately slowed down my progress to almost halt.

When i finished most of the mechanics for the game and got to the most important part – making content – i simply couldn’t find any more willpower because of the tedious process involved in making hundreds of enemy waves. I believe someone with better coding skills could make a level editor and finish it much quicker, but with my knowledge, i had to do everything by hand and i kind of lost the motivation. Let’s delve a bit deeper into the problem.

One of the things i really love about Unity is use of Prefabs. As someone who is not a programmer by trade, it was easy for me to relate to something drag and droppable, an object with belonging properties that is simple to instantiate and easy to manipulate without much hassle. Two years ago, one of my first questions on Unity Forums was about something that i didn’t even know what is called back then – Nested Prefabs. I couldn’t understand why instantiated objects could have child objects that have child objects who also have child objects can exist in the scene, but not as a Prefab. That pretty much broke my building blocks concept of making a game.

Untitled-Diagram.pngHarsh red line reality check

As you can see, i imagined the waves of enemies to be compiled of squadrons (as well as waypoint and single enemies, about which i wrote in my previous logs) which would be a Prefab object with lots of children objects (singular ships and their engine jets, weapon, tags for missile homing and so on). Unfortunately, Unity supports only one level of vertical nesting in the project, so while an object can have literally hundreds of children, non of them can have their own. Since i read that the Nested Prefabs are something that was planned more than five years ago and not yet in the making i tried a few assets that simulate Nested Prefabs but to no avail. You’ve probably seen the horrible reviews on the Asset Store, most of them are abandoned, buggy, slow or complicated. Since i found no decent asset that will enable me to work the way i imagined, i resorted to the usual workflow of instantiating a Prefab and populating it with components that i needed.

GetSet.pngThe usual get this/set this workflow

It wasn’t too hard for single enemies, all i needed to do was instantiate appropriate objects on designated locations and that’s it. I learned a lot of things in the process, getting and setting the properties of many available components and their variables, the importance of pooling and the way it works, managing performance and so on. I must admit i had more than a handful of situations where i didn’t know how to overcome some of the challenges, but i’m grateful for them since they were an opportunity to learn something new through problem solving. When most of the stuff that make the core of the games look and feel were finished, the harder part of making a game in the true sense of words came. I won’t repeat myself too much, you can read more about my process of making waves in this and this log. In short, instead of dragging and dropping positions where i want the ships to spawn, assign the wanted behavior to each one depending on the wave structure and simply save all that as a prefab i need to:

  • Have specific spawner types. That means single enemy, waypoint enemy and squadron enemy spawner with their locations.
  • Make a specialized movement FSM’s for almost every enemy type that will dictate movement direction and scale of ships and ships’ children. For example, engine jet needs to be a separate object so it doesn’t flash with the ship upon bullet contact but it must be properly rotated and scaled depending on the spawning position and spawner parent of the parent (yeah, even i lost it while reading).
  • Assign more elements to pool which slows down the compilation time and time required to start the game. Instead of pooling one ship with all the needed components i need to pool the ship prefab, jet prefab, weapon prefaband in some cases multiple weapon prefabs so the pool size for ships is actually at least three times the size in terms of object number. I’m fairly certain that it’s better to have fewer objects to instantiate regardless of their complexity (number of components attached).
  • Manually set the spawning position of each ship in the wave. This is the worst part, it got me completely devastated. I need spawners for assigning some general behaviors and general screen position, but all the fine arrangement of ships in the wave must be done by hand. Not completely, but i need to put the ships in the scene so i can get their coordinates, then copy them into the spawning FSM of the squadron. Sure, i need to position the ships with nested prefabs too, but only once and that’s it. Doesn’t sound like much of a fuss, but imagine having hundreds of waves to make with some of them having double digit number of enemies that need to be repositioned upon spawning.
set-position.pngSet Position, Set Position, Set Position

I’m sure some people don’t even use prefabs but create instances and populate them on runtime and i presume some more C#-savvy people will find nothing unusual in this and develop their own systems for handling the situation, especially big teams. But i’m neither of those and, for the time being, i really need nested prefabs to finish what i’ve started. Prefabs are great game building blocks that further upgrade great tool that Unity already is and we should be really glad they are taking into account the needs of small or one man teams. I’m anxious to see further improvements that the new prefab system will bring to the table in the future versions.

 

 

The post Ode to Nested Prefabs from a noob indie dev appeared first on Fat Pug Studio.


View the full article

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • What is your GameDev Story?

    In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

    (You must login to your GameDev.net account.)

  • Blog Entries

  • Similar Content

    • By Anton Kormishenkov
      To The Capital 2 is a game in the genre jRPG with classic turn-based battles in which you have to travel together with four heroes visiting a lot of cities, dungeons, mysterious places and fight with various bosses.

      It took almost 2 years to develop and finally we have reached this important event as the release of To The Capital 2!

      Big thank you to everyone who has followed our project. I hope our game will give pleasure to fans of the genre of jRPG, and beginners in it.

       
    • By Nick Griffith
      I'm building an innovative 2d platformer game, more on that later probably.
      I've created basic mechanics, some basic enemies, wall jumping platforms and the like. But I just need MORE to fill my levels with.
      Could you guys give me ideas for enemies, items, mechanics, basically anything(art would be appreciated, but I just need ideas)
    • By InTheBeef
      As stated, I'm looking for potential opportunities to just learn &/or recieve income, as well as make some game dev friends!

      I am an eager to learn amateur, my only experience is in modding Nintendo games (Zelda Wind Waker, or ALTTP) using primarily Autodesk 3DS Max.
      I doubt I could create high detail models or textures, I much prefer simplistic characters with solid color, often cel shading.
      I believe I am decent at optimizing models and textures, I am not very familiar with code but I'm not dumb (In the event file formats need to be converted, etc).
      I can attempt to create low detail sprites and adhere to specific palettes. (24x40 pixels maximum)
      I have not yet put together a portfolio, and intend to in future.
      If you would like for me to try and work with you, you can contact me at twitter.com/InTheBeef or InTheBeef#1252 (discord).
      note if you view my media on twitter you can see a few things I've made/modified.
    • By Titanomachy Studios
      Project Name: Condors Vs. Ocelots
      Team Size: 15ish
      Genre:Strategy RPG
      Engine: Unity
      Roles Available: Currently in need of 2 2D sprite artists, 2 2D concept artists, and then finally 2 programmers. If you feel as if you can offer the team something more that isn't listed, we are always open to making an exception, just send your resume/portfolio to us!
      Project Length: Currently planning on release Q1 2020.
      Compensation: Rev-share
      Project Description: Condors and Ocelots have been at war for generations. Battles have left some settlements in ruins. Others teem with refugees. Even away from the fighting, towns and villages suffer from having their fighting-age citizens lured away or conscripted by one faction or the other. Banditry is also rife -- since the Condors and Ocelots focus on the front lines, and largely neglect the parts of their respective dominions which aren't militarily important or located near their bases. The mysterious faction, Goatverlords, comes in and antagonizes both claiming rule of the land. They must work together and against one another to win the ultimate struggle.
      Project Status: Pre-design is completely done and we are starting on development of our builds.
      Send emails to careers@titanomachystudios.com
       
      Our store page can be found here, https://play.google.com/store/apps/developer?id=Titanomachy+Studios
      Our website here,
      http://titanomachystudios.com/#/
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!