Saturday, September 27, 2014

CSG Post 2: The Hundred Enemy Problem

Just recently in my CSG Capstone class I over heard a conversation about the use of the SendMessage() Method in unity and how it is much slower than direct calls or using Events. This is certainly true. Having to Search through an entire GameObject in search of the passed in method name is incredibly inefficient. However I had just recently been working on a problem with another project of mine and it seemed to me that the only elegant solution to the problem was to use the SendMessage() Method.
The Problem is that when you develop a game you may have an undefined or variable amount of enemy types each being controlled by a corresponding script that will only function for that enemy type.  That works well enough for just a few enemies and maybe you want to add a bit of inheritance into the mix and have all your AI scripts inherit from a script that has a health property on it. The Problem comes in when you want to be able to detect that an object is an enemy and apply damage to that object generally so that whether it be a Flyer enemy or a Walker enemy you can call just one line of code to apply the same Operation to several different types of script instances. The three ways that are typically used to pass data back and forth between objects are not valid solutions. Direct Calls issues the Immediate problem of not being able to make direct calls. If we don't know what script we are using then we don't know what calls we can make. Events would work but for a game that may need Hundreds of enemies active at once, passing variables to over a hundred different instances of somthing that may not even need that informations does not sit well with me. And of course SendMessage is actually a very good solution to the problem except it does not work because that is also highly inefficient.

One solution that I came up with before writing this was to instead of having entirely separate scripts for each enemy, grouping enemies together based on how similiar their behaviors were and then just changing certain variables to allow them to have their proper behavior. This Minimizes the amount of calls you have to do and the amount of different tags you have to set. It is not a perfect solution by any means but it would allow you to easily have a hundred enemies without becoming to inconvenienced . The Solution that I thought of as I was writing this is a much better solution though. Rather than having One script for each type of enemy and a script that it inherits from you could have just two entirely separate scripts. One script for the enemies unique behavior and one script for the enemies common behavior. The common behavior script would be on every prefab of an enemy and would be called when needed by unique script. This way any generic methods can be called by external scripts and the unique behavior script also has access to it for its own behavior.



Friday, September 26, 2014

CSG Post 1: Here We Go Again

Another semester of the CSG program another set of forced blogs. Im going to take my first blog to just give an overview of Raid+ affairs. The team that I'm with for my Matc capstone class (Raid+) is currently making a game called Scoundrels of Yen(SOY). SOY is a Collectible Card Game that uses a board game type interface. The Designers are currently hard at work finding the Fun. Artists are doing tonnes of cool concept art. And programmers are hard at work setting up the framework for the game. We are currently using service called Get to Done for our performance tracking and so far that is working pretty well. The Tech team is using Source Tree and BitBucket for version control. A good Start to the Semester.