Sunday, December 7, 2014

Unity How To: Loading Assets at Runtime

This is the first installment of a new series in which I intend to create tutorials on various aspects of using the Unity game engine. These are intended to be aimed at those who know the basics of the engine but don't yet have extensive knowledge of it. I hope that these are particularly of use to artists or designers who are getting their feet wet with scripting in the game engine. If there are topics that you would like me to cover in a future post, I encourage you to share them in the comments section. Now, without further adieu:

Loading Assets at Run Time

What use is this?

In Unity, most assets are assigned while working in the scene view. An example is when a texture is assigned to an object or an asset is dropped into a slot on a script in the inspector. This is how Unity determines which assets it has to have loaded at any given time and determines which assets are included in a build. However, there are times when loading assets into the inspector can be tedious or inappropriate.

For example, if a single character has many 50 outfits that are implemented as alternate textures, then loading all 50 textures into the inspector becomes tedious and a waste of memory, as Unity will load all 50 textures into memory. An alternative approach is to load the outfit at the start of the game and then unload the rest of the textures. This allows the game to reclaim unused memory and run more smoothly.

A Simple Example:

In this example, we will create a simple scene that changes the texture of an object when the scene starts. There are a few items that are neccessary to set up in advance. Only assets that exist in the Resources folder can be loaded at run time. Simply create a new folder at the top level of the Assets folder and name it "Resources", as shown here. In that example, the material "Blue" can be accessed while the assets in the "SampleProject" folder would be inaccessible.


Now, we need to add an object to our scene to place the material on. Create a blank scene and add a cube to the scene. Position it so that it is visible to the camera. It should look similar to this. I have elected to add a Red material to the cube to emphasize the transition, but this is not necessary.


Now, we need to create the script below and add it to the game object we added to the scene:


The basic syntax for loading an asset from the resources folder is shown in line 11. That syntax is "Resources.Load<Type>(Asset_Path)". In the Type location, the type of asset is specified. In this example we are loading in a Material, but this can be changed to accommodate other types such as a Game Object in the case of loading a prefab. The "Asset_Path" is a string that holds the location of the asset relative to the Resources folder. I have elected to create a string variable in line 6 which holds the location of the asset as a matter of good practice, but this can be hard coded.

Now, simply drag and drop the LoadResources.cs script onto the cube object that was created earlier, and press play. When the simulation is run, the "Blue" material should be accessed and assigned to the cube.

Talking to the Player (Part II)

In my last post, I talked a little about creating a teachable moment in a video game though breaking the 4th wall to address the player directly. However, there is another more subtle and arguably more effective way to cause a player to question his beliefs. Ask the player a question that they cannot answer.

Now, there is a lot to say on this topic and I cannot summarize it better than the good folks over at Extra Credits (link below), so I encourage you to listen to what they have to say. However, what I intend to explore here isn't what the player learns from the choice itself. I'm interested in exploring the mechanics of presenting that choice effectively.



I'm going to use an example that recently forced me to pause the game and think in just such a fashion. The example comes from Dragon Age: Origins. Be warned, there will be spoilers.

Still with me? Good. The set-up for this scenario involves the dwarves and their centuries long battle against the darkspawn. Originally, there were 11 great dwarven kingdoms connected by a large network of underground tunnels known as the Deep Roads. The Darkspawn also live underground and have been constantly attacking the dwarven kingdoms through the Deep Roads. The dwarves have steadily been pushed back; only 2 of the original 11 kingdoms remain.

This is where the Golems come into play. Centuries ago, a dwarven inventor figured out how to create Golems, soldiers of living stone. For a time the dwarves used the golems to hold the line and even push back the darkspawn, but the artifact used to create the golems was lost.

In the game's storyline, the player eventually goes into the Deep Roads and finds the lost artifact that was used to create the golems. However, when they do they are met by the spirit of the dwarf who originally created that artifact. He reveals that the reason he sealed it is because the secret of the golems is that creating a golem requires the sacrifice of a living person – their soul is imprisoned in the golem and used to power it. At first, he only used volunteers, but then criminals were used and eventually the dwarven king started ordering his political enemies be used. He then begs the player to help him destroy the artifact rather than allowing it to enslave more souls. The player is then faced with a choice of recovering the artifact or destroying it for good.

The choice is re-enforced within the game's mechanics. Preserving the artifact allows the player to add Golems to the army they are trying to assemble and makes them usable during the game's final battle, but one of the characters in your party feels strongly enough about the evil of the artifact that they will leave the party and fight you.

The way the choice is framed is also significant. The choice is either-or ; there is no middle ground option because the player cannot both destroy and preserve the artifact. This prevents the player from ducking the decision. It is also important that neither decision is presented as the clearly superior choice – both of them will require sacrifice.

Furthermore, the decision is treated seriously by the game and carry consequences. There are no snide comments to the player to make light of that decision.


All of these elements are significant in crafting a decision that forces introspection from the player.

Talking to the Player (Part 1)

Recently, something happened that hasn't happened in some time. I was playing a game and the story presented me with a difficult choice. I thought about it briefly, then stepped back from the keyboard and thought about it some more. It made me question my beliefs. When I came back and made the choice, I felt like I'd also learned something about myself. Presenting this kind of choice to the player is one way that gaming can move beyond simply being viewed as entertainment and become respected as an art form.

I have seen games make attempts at creating these teachable moments in two main strategies. In the first, the game at some point breaks the 4th wall and talks directly to the player. In the second, the game creates a moment where the player is faced with a choice that prompts their own introspection. Both strategies have a set of criteria that has to be effective for the message to resonate, and I will explore some of the mechanics necessary for creating effective teachable moments. Be warned, this post contains spoilers.

In the first strategy, in which the game will break the 4th wall and talk directly to the player, I can think of no better recent example of doing this well than Spec Ops: The Line. Now, much has already been written about this game, both its message and its plot. What doesn't get mentioned much is that the set-up for that final sequence in which the hero is called out for his actions. For that call-out to be effective, the player needs to feel agency over their actions up to that point.

This feeling of agency is reinforced through the very mechanics of how the player's actions are presented. For example, there is a time in the game when the player's squad is surrounded by a hostile crowd. These people aren't soldiers, but they greatly outnumber the player and they're angry. As they slowly close in, the player has only his 2 squadmates and his gun. Many players report at that point that they start firing into the crowd, killing the civilians. As soon as they start firing, the crowd flees. Mechanically, no prompt was given and the player wasn't forced to kill them. In fact, if the player stays calm and fires into the air, the crowd will still flee. The player chose to fire into the crowd – chose to take that action in a way that makes them feel like they own it. This makes the call-out at the end all the more effective – because the situation is constructed in a way to make the player feel like they had agency for the very actions that are being called out.

An example of this being done poorly is the recent Far Cry 4. If you're not interested in spoilers then you should stop reading now.

Still with me? Good.

The player takes the role of a person returning to their native land (which is embroiled in a civil war) to spread their mother's ashes. The player then gets embroiled in the civil war. At the beginning of the game, the player meets and escapes from Pagan Min, the country's dictator. As the storyline progresses, the player is forced to choose between rebel factions and whether or not to kill main characters. Much later in the game, the player confronts Pagan Min again. The Min will call out the player for his actions, even going so far to point out that the player doesn't even have a motivation for what hes doing.

Yet, this attempt at calling out the player is hampered by the game itself. For instance, during their first meeting, Pagan Min tells the player that he has cleared his calendar so him and the player can “tear stuff up”. There is an optional ending where the player doesn't escape from Pagan Min and instead he takes you directly to the place you wanted to place your mother's ashes by helicopter. After you have done so, then he allows you to depart the country by helicopter. This allows you to complete the game in under 30 minutes without ever once picking up a gun. As the screen turns to black, however, Min makes one final statement: “Do you feel better now? Get that out of your system? Good. And maybe now we can finally shoot some goddam guns.” He isn't speaking this line in character - he has no reason to. He is speaking to the player, asking them if they're done with their adventure in nonviolence and can we please get back to the gun play.

That style of self-aware humor is sprinkled throughout the game and interferes with the game's attempts to question the actions of the player. The player is being continually reminded that they're playing a game, which encourages the player not to take the events too seriously and instead lay the blame for their action's on the game's narrative and their protagonist instead of taking ownership of their actions.

This isn't to say that Far Cry was a terrible game or the Spec Ops was the best game ever. However, Spec Ops' combination of taking itself more seriously and giving the player as much agency over their decisions as possible made their message calling out the player's actions much more effective. If one wishes to call out a player directly, these are good lessons to learn.

Monday, May 12, 2014

Facebook, Occulus, and the War for Virtual Reality

     Jim Sterling is the creator of the Jimquisition, a popular game consumer advocacy video series. He acts as a critic for the game industry, talking about complex issues facing the industry while taking on his signature persona. The Jimquisition puts out a new video weekly and is widely regarded as a significantly influential voice for consumer advocacy.

     Several weeks ago, he did a video in which he discussed the stunning acquisition of Occulus by Facebook for $2 billion. The reaction from many gamers was sharply negative. Many users mistrust Facebook and were upset that Occulus, which got its start from a crowd-funded Kickstarter campaign, would sell out and in so doing turn its back on the gamer grassroots that supported it in the first place. Jim, however, takes a more considered look at the issue and made some excellent points. I've embedded the video below:


     Overall, Jim isn't upset at the buyout and makes the point that Facebook has a much better track record for not destroying or mistreating the companies that it buys than the largest players in the gaming industry does. If Occulus had to be bought, Jim argues, then Facebook is far from the worst buyer to be found.

     While I agree with Jim's point about Facebook, I don't think he goes far enough. The fact of the matter is, Occulus did have to be bought at some point. Occulus raised ~$2.5 million on their initial kickstarter, $16 million from Series A, and $75 million in venture capital. While this is certainly an impressive figure, developing new hardware is extremely expensive to begin with, and Occulus has also been running an impressive outreach and marketing campaign to build up interest in the technology. Continuing the process is going to be even more expensive. Occulus quite simply was going to need another cash infusion at some point.

     The timing is also an important factor, as the week before the acquisition Sony unveiled its own Virtual Reality headset, the Morpheus. Sony represents a large, well-funded competitor entering what is essentially a speculative market. For all the hype Occulus has managed to generate, nobody really knows for certain how successful the headset is going to be or how many users will decide to buy. Its even less certain whether the market will have room for 2 competitors.

     Faced with that reality, the longer Occulus waited the less of a good bet they would look like. If Facebook is sincere about allowing Occulus to continue to manage itself, then this deal is purely a gain for Occulus - they gain the financial backing necessary to compete with Sony and make Virtual Reality a reality.

Sunday, April 27, 2014

TED Talks: Marco Tempest in AR

The Medium is the Message.

In his presentation to TED Talks, A magical tale (with augmented reality) , magician Marco Tempest talked about magic and storytelling. It didn't have any overt agenda, instead focusing on entertaining the audience. Marco spoke without a powerpoint, charts, or graphs of any kind, but it did have a twist: the talk was done using Augmented Reality.

Marco Tempest was talking into a device that recorded him, his motions, and overlaid special effects on the video being shown on the video screen in real time. He used these special effects to both entertain and to provide visuals in order to illustrate his points. They blended with the magic tricks he was performing and greatly enhanced the talk. And that was his argument.When asked for ideas for applications for Augmented Reality technologies, people tend to think of AR in terms of displaying data, like what they see in movies like Iron Man or Minority Report. They've put AR into a box. Marco Tempest, without directly invoking this, simply shows how AR can also be used in entertainment.

From a technical perspective, Marco made excellent use of the AR integration into his presentation. He was awash in visual props to help make his points and matched his pacing to the visuals he was using. For instance, he covered more ground in his 6 minutes than would normally be advisable as the audience might not be able to keep up. However, the flurry of visuals emphasized his words. He also divided the talk into 3 major points. Each of those points opened with a quote and a pause before and after the quote. While the audience was treated to a special effect while the quote was being shared, it also provided a brief pause for the audience to process what they'd seen thus far. Using these techniques, he was able to present his information at a faster than normal pace as well as direct his audience's attention. This is an excellent example of how AR can be used outside the context of eye-wear.

The medium is the message.

Monday, March 31, 2014

Examining Ways to Promote a Company on Social Media

     In the last 2 decades, social media has gone from a curiosity to an indispensable marketing tool. While social media has not supplanted traditional marketing campaigns entirely, these tools offer several advantages over traditional campaign tools. For instance, many consumers have become less responsive to traditional marketing avenues and a well run social media campaign is an effective way to bridge the authenticity gap. Further, social media is free to set up and use, making it both cost-effective and attractive to small firms and start ups.

     While social media is powerful, there are right and wrong ways to market yourself or your company. There also isn't such a thing as a one-size-fits-all strategy when using these tools. Your company's strategy should be built around your company's individual strengths, mission, and history. For example, take IBM.



     IBM is a company with a long and storied history of being involved in major technological innovations and moments in American history. Its social media strategy takes advantage of this by sharing pictures from the company archives depicting historic projects they have been involved in. The immediate effect is to shares positive nostalgia and contribute to giving people reason to be proud to be a part of the brand. These posts also don't feel like advertisements, which makes them more widely shareable.

     This also fits into IBM's overall media strategy. In there social media, there are no hard sells or promotions. In addition to sharing the company's photo archives, IBM shares and retweets articles about cutting edge technologies and deep thoughts. In this way, IBM positions itself as a leader on the edge of technology. It gives the company a more trustworthy “personality” and the company hopes that when consumers are making a choice, those brand associations will influence customers to chose their brand.



     Blizzard Entertainment's social media strategy showcases a way to build a company's presence around its fans. In addition to sharing and tweeting about upcoming events the company is involved in, Blizzard also shares fan art, costume contests, game achievements, and other fan-generated content on its facebook page. This is a great way to build their community and show appreciation to their fans and seems like a particularly effective strategy for catering to the fans of their games.

Monday, February 10, 2014

Why I'm at MATC

Recently, an instructor asked me for a copy of my Resume. When he reviewed it, he promptly asked me why I'm not pursuing other work. It is a question I get asked often. After all, I have a bachelor's degree in Biology. Why am I going back to school at MATC?

There are a number of reasons that I chose to come to MATC and change career paths.

When I studied biology at Carthage College, I knew I wanted to be a researcher. I wanted to unlock the secrets of the cell and contribute to science. After I graduated, I spent a few months working as a lab tech to get experience. I was already wavering on whether I wanted to continue that route, as I wasn't enamored with the idea of continuing on to grad school. Working as a lab tech for those few months made it clear to me that I didn't want to continue down that road.

After I quit my job in the lab, I returned to work at the family business. It was good work, and while it wasn't a bad job, my heart really wasn't in it. I didn't want to continue manufacturing cages the rest of my life. I wanted to work with computers, and more specifically I wanted to work on making games.

I considered a number of schools in the area, but MATC stood out. I had always had both a talent with and love of computers. While many schools in the area have IT degrees of some description, MATC is the only school that also has a Computer Gaming program. I knew a number of individuals in the CSG program and had heard good things. The instructors had real-world experience, which I felt was a great resource.

When I entered the program, I was one of only a few people in the class with previous programming experience. When the class was divided into groups, I was chosen as our group's leader. I was reluctant at first, but I grew to enjoy directing the project and studying Agile and Scrum project management techniques. I worked hard to make the group successful, and my efforts were noticed by my instructors. I was given opportunities to work on projects for companies my instructors owned, which has been a great experience.

I hope to become a successful Game Developer and share my love of games with others. That is why I am studying computers and game development at MATC.