Warning: Creating default object from empty value in /home2/nasim55/public_html/saadkhawaja.com/wp-content/plugins/contact-form-7/includes/controller.php on line 131
Saad Khawaja - | Game Development | C# | Unity | Unreal | C++

Solution: ‘MEMORYSTREAM’ IS CORRUPTED! REMOVE IT AND LAUNCH UNITY AGAIN! [POSITION OUT OF BOUNDS]

By | Tutorials | 3 Comments

You must have come across this error which is why you’re viewing this page:

‘MEMORYSTREAM’ IS CORRUPTED! REMOVE IT AND LAUNCH UNITY AGAIN! [POSITION OUT OF BOUNDS]

The bug was reported to Unity here:

https://issuetracker.unity3d.com/issues/the-file-memorystream-is-corrupted-remove-it-and-launch-unity-again-position-out-of-bounds

 

The proposed solution from the message is: Launch Unity again which does not work. Even restarting the system and relaunching Unity does not work.

The Unity team was unable to reproduce this issue so as a result, there is no official solution. However, after hit and trial I have deduced that the problem is caused by Unity Remote – attached iOS Device.

 

Solution:

1. Open Editor Settings (Edit->Project Settings->Editor)

– position out of bounds

 

2. Select device to None

3. Save Project

4. Quit Unity

5. Relaunch Unity and the problem must be solved.

Instant Hi-Res Screenshot

By | Freebies | 6 Comments

So upon popular request, I’ve decided to make an editor extension of my Screenshot Script.

It now works like a charm! Just import the package in any project and goto -> Saad Khawaja -> Hi-Res Screenshot

 

You can now take High Resolution Screenshots of your Unity Game right from the Scene View as well at the click of a button!

Features:

  • Take the Hi-Res Camera Render Screenshot (with/without alpha channel)
  • Set your own resolution
  • One click from the Scene/Game View

 

Screenshots:

Screen Shot 2014-10-21 at 3.38.02 am

 

 

 

Download:

http://www.saadkhawaja.com/freebies/InstantScreenshot.unitypackage

Tower Defense Game Kit – Fieldrunners Clone

By | Game Kits | No Comments

Demo | Download from Unity Asset Store

The package contains a full fledged Tower Defense game kit starter code.
A complete structure of enemies, waves, etc is included to get you started.

The best part is that this package follows the practices of successful TD games like FieldRunners as it is Sprite Based 2D.

Sprite Sheets containing images of different angles are used which is a very efficient approach as compared to using 3D models.

It is also a good learning point for beginners and advanced developers on how to create a tower defense game using 2D sprites with sprite switching.

A* Algorightm is used for pathfinding – grid based movement is used for enemies. A complete coding structure with concepts like inheritence, polymorphism etc is there so editing/adding is extremely easy for developers.

-> One Tower included by default – (Can easily add more)
-> 3 Enemies included – Dog, Car, Human.
-> A* Algorithm for PathFinding.
-> Efficient for Mobile Phones
-> 2D Sprite Based – Not 3D.
-> Complete TD Game Structure Included
-> Grid Based – Edit Grid size, alter movement etc easily
-> Multiple Path Finding ways – Euclidean Distance, Manhattan Distance etc.
-> Easy to Understand
-> Easy to Edit and Modify
-> Documentation Included
-> C# Code

2D Endless Jumper Game Kit

By | Game Kits | 5 Comments

2D Endless Jumper Toolkit is a full game template for creating infinite jumper games of any kind. e.g. Doodle Jump in Unity3D, MegaJump etc.

The package has all the code necessary to create a game with varying difficulty – and optimum performance for Mobile devices.

Features: 
– Unity 2D Sprites Used
– Full Gameplay Mechanics (jumping, enemies, tiles, powerups, scoring)
– Accelerometer Control
– Dynamic Level Generation
– Object Pooling – Efficient for Mobile Devices
– Advanced Game Settings (probability of tiles, powerups, enemies etc)

 

Demo

Asset Store Link

 

 

2D A* Grid Based Pathfinding in Unity3D

By | Freebies | 3 Comments

This is a 2D Grid Based Pathfinding solution especially for Tower Defense games like FieldRunners etc.

The sample instantiates enemies at a random grid tile and they move along the grid to the end position. Only Unity 2D Sprites are used for enemies, grid and background.

You can customize the grid size and other variables – This is a sample code to learn and re-use if needed.

Demo (Web Preview)

Download (Yes, it’s free!)

Play a specific frame of Animation (Legacy)

By | Snippets | 2 Comments

Unity does not have a method to goto a specific frame per say. But you can move to a specific time interval of an animation using Gameobject.animation[“name”].time – Legacy Animation

So in short, you can actually goto a specific frame by finding the time of the animation at that particular frame. e.g. If the animation speed (visible in the animation window) is 24 fps: It means 24 frames are rendered in 1 sec.

The first frame will be at 1/24 * 1. The second will be at 1/24 * 2. and so on.

So this snippet will do the trick:

gameobjectname.animation.Play ("Take 001");
gameobjectname.animation.Stop ();
gameobjectname.animation["Take 001"].speed = 0; //to make the animation pause
gameobjectname.animation["Take 001"].enabled = true;
gameobjectname.animation["Take 001"].time = (1f/24f)*frameNumber;

Enough. No More Flappy Clones Please!

By | Uncategorized | One Comment

According to data from March 2014, Over Sixty ‘Flappy Bird’ Clones Hit Apple’s App Store Every Single Day.
The number is bound to be way higher on Google Play Store.

Do you know what this means? Not only are the stores littered with crap flappy clones, but the forums, groups, social media – every where! Developers are advertising their Flappy clone as if it’s the next big thing.

This Flappy clone madness has to stop now!

flappy-bird

Flappy Bird caused a sensation after rising from obscurity to become one of the most downloaded mobile games on both Apple and Google’s online stores.

Instead of focusing our energies to copy a game that frankly, takes any developer a day to make, why can’t we work on original ideas?

It gave indie developers a sense of hope that even they could make it big with a little luck and effort.
But instead of focusing on casual game ideas like flappy bird, developers started creating the exact clones.

Now after all Flappy Bird clones are beginning to drop on the charts, it’s time we go back to the drawing boards and start working on original ideas.

Get Time from the Server

By | Snippets, Uncategorized | 3 Comments

A common error that developers make is that they use the time on the device for various game play elements.

For e.g. A game that requires the user to wait 2 hours before making another element.

This can be easily hacked by changing the device date/time. So, in order to stop cheating, you must get time from the server and compare the current time with that.

 

The easiest solution would be to make a PHP page and print time in it.

Then use WWW in Unity to query the page and get time.

 

PHP

  1. <?php
  2. print date(“G.i:s”, time());
  3. ?>

UNITY

void Start () {
        StartCoroutine("getTime");
 
    }
 
    IEnumerator getTime()
    {
        WWW www = new WWW("http://www.saadkhawaja.com/gettime.php");
        yield return www;
 
        Debug.Log("Time on the server is now: " + www.text);
    }

Move a 3D Object with Mouse – and make it collide

By | Snippets | 2 Comments

A basic problem that many Unity developers face is that they use Transform.Translate or update Transform.position of an object and expect it to collide with other objects.

This is not the case. When you’re using Transform.Translate or Transform.Position, you’re essentially just teleporting the object to that position. Hence, there will be no collision with intersecting objects.

Fortunately, Unity has provided a function rigidbody.MovePosition which takes care of this. The snippet below moves a 3D object (on which it is attached) with the mouse and collides with all objects that come in its way.


using UnityEngine;
using System.Collections;

public class MoveWithMouse : MonoBehaviour {



	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	

		Vector3 v3 = Input.mousePosition;
		v3.z = 10.0f;
		v3 = Camera.main.ScreenToWorldPoint(v3);

		Debug.Log(v3); //Current Position of mouse in world space

		this.gameObject.rigidbody.MovePosition(v3);

	}



}