background preloader

Unity3D

Facebook Twitter

Unity 3D Best Practices: Part 1. We’ve been developing games with Unity for a while.

Unity 3D Best Practices: Part 1

As most of our games are targeted for mobile devices, one of our main concerns on the development process is having our projects well structured and optimised. There are a lot of simple tips and tricks we’ve been using which make all the difference on any project’s overall performance. In order to demonstrate each topic’s usefulness, I’ll be presenting profiling data retrieved from a demo, running on an iPad Mini. Always cache references to components you’ll need to use on your scripts. Accessing a game object world position from its script is easy, all you need to do is call transform.position. When accessing transform, renderer or other built-in component getter inside a class it’s internally calling a GetComponent<ComponentName>() which is slow. I’ve created a simple demo where 800 boxes are moving around and bouncing with each other.

Figure 1 – Caching Components Figure 2 – Using GameObject.Find(…) vs Cache Reference Related In "Games" (Saving...) (Saving...) Unity 3D Best Practices: Physics. (Note: This is a follow-up post to a previous article on optimisations and best practices for Unity development).

(Saving...) (Saving...) Unity 3D Best Practices: Physics

This second part in our series will be entirely focused on Unity’s Physics engines. I’ll present, similarly to the previous article, simple topics which are easy to use and will optimise the physics engine usage. Let’s begin! All game objects, if not configured, are created on the Default layer where (by default) everything collides with everything. This is quite inefficient. Establish what should collide with what. For each new layer, a new row and column is added on the Collision Matrix. By default, when adding a new layer, the Collision Matrix is set for that new layer to collide with every other existing one, so it’s the developer’s responsibility to access it and setup its interactions. Unity 3D Best Practices: Part 1. (Saving...) (Saving...) Unity 3D Best Practices: Physics. Procedural Audio Generator for Unity3D. Tip of the day. May 2013 Tip #67 – Get and set build order of scenes You can get access to the build order for scenes in your editor scripts by calling EditorBuildSettings.scenes.

Tip of the day

This allows you to control what scenes are included with the build through your editor code. public class SceneDump { [MenuItem("Codefarts/Dump Scenes")] public static void Dump() { var parts = from part in EditorBuildSettings.scenes select string.Format("{0} - {1}", part.enabled, part.path); Debug.Log(string.Join("\r\n", parts.ToArray())); }} Tip #66 - QueueGameViewInputEvent Need to send simulated user input to the game window?

Tip #65 – Get asset path of UnityEngine.Object Below is a simple bit of code that will attempt to retrieve the asset path of the prefab stored on disk. /// <summary>/// Gets the source path to a prefab if any./// </summary>/// <param name="prefab">The prefab reference to get the asset path for. April 2013 Tip #64 – Detect when unity compiles scripts Tip #63 – Right click “Open with Unity” March 2013. Procedural Content Generation Wiki. Cloud9 IDE – Your code anywhere. Procedural Audio Generator for Unity3D. (Saving...) (Saving...) Unity 3D Best Practices: Physics. 46 Tips & Tricks for 2D mobile Performance in Unity. If this is your first jump into the world of Unity, my first tip (this one’s a freebie) is to stop trying to use it like other languages and environments.

46 Tips & Tricks for 2D mobile Performance in Unity.

You will be using GameObjects, you will be adding multiple script components, and you will have to think differently. When I first started, my approach was to largely ignore prefabs (or use them like Flash’s display list) and get a copy of Box2D running. Painful as it is to deviate, get ready to put in some work! Without further ado, let’s get started: Physics: -Use the built-in physics.It might seem like a waste of cycles to have a fully 3D physics engine running the show for a 2D game, but bear in mind that the Nvidia PhysX engine will be running in Unity’s native core.

-Try to use a 1/1 scale. -Get your object Mass right. -Mesh colliders can be slow compared to primitive box/sphere colliders. -You can simulate more complex shapes by combining primitive colliders. -Objects with a collider but no RigidBody are considered static. Gamedev / Unity3D Resources. Unity3d 3.5 PathFinding. Unity Tutorials > New Features in Unity 3.5 > Pathfinding basics in Unity 3.5 Tutorial.