Lesson 2: Unity 2D Project Setup
Welcome to Lesson 2 of "Build a 2D Platformer from Scratch"! In this lesson, you'll learn how to properly set up a Unity project specifically optimized for 2D game development. This foundation will ensure your platformer game runs smoothly and follows Unity's best practices.
What You'll Learn in This Lesson
By the end of this lesson, you will be able to:
- Create a new Unity project with 2D-specific settings
- Organize your project with a proper folder structure
- Configure Unity's physics settings for 2D gameplay
- Set up the camera for optimal 2D viewing
- Understand the key differences between 2D and 3D Unity projects
Why Proper Project Setup Matters
Setting up your Unity project correctly from the start is crucial for 2D game development. A well-organized project structure makes development faster, reduces bugs, and makes it easier to collaborate with others. The 2D-specific settings we'll configure will ensure your game performs optimally and looks crisp on all devices.
Step 1: Creating a New Unity Project
Launch Unity Hub
- Open Unity Hub on your computer
- Click "New Project" in the top right corner
- Select "2D (Built-in Render Pipeline)" template
- This template is specifically designed for 2D games
- It includes optimized settings for 2D development
- Name your project "2DPlatformerGame" (or your preferred name)
- Choose a location on your computer to save the project
- Click "Create Project"
Why Use the 2D Template?
The 2D template provides:
- Optimized render settings for 2D graphics
- Pre-configured physics for 2D gameplay
- Proper camera setup for 2D viewing
- Built-in 2D tools and utilities
Step 2: Organizing Your Project Structure
Create Essential Folders
Right-click in the Project window and create these folders:
Assets/
├── Scripts/ # All C# scripts
├── Sprites/ # 2D images and textures
├── Animations/ # Animation files
├── Audio/ # Sound effects and music
├── Prefabs/ # Reusable game objects
├── Scenes/ # Game levels and menus
├── Materials/ # 2D materials and shaders
└── Settings/ # Project configuration files
Pro Tip: Folder Organization
- Keep related assets together in logical folders
- Use consistent naming (PascalCase for folders)
- Don't put everything in the root Assets folder
- Create subfolders as your project grows
Step 3: Configuring 2D Physics Settings
Access Physics Settings
- Go to Edit > Project Settings
- Click "Physics 2D" in the left sidebar
- Configure these settings:
Gravity Settings
- Gravity X: 0 (no horizontal gravity)
- Gravity Y: -9.81 (standard downward gravity)
- Default Material: None (we'll create custom materials later)
Physics 2D Settings
- Velocity Iterations: 8 (for smooth movement)
- Position Iterations: 3 (for accurate positioning)
- Velocity Threshold: 1 (minimum velocity for physics)
- Linear Sleep Tolerance: 0.005 (when objects stop moving)
- Angular Sleep Tolerance: 0.005 (when objects stop rotating)
Pro Tip: Physics Optimization
These settings provide a good balance between:
- Smooth gameplay (higher iterations)
- Performance (not too high iterations)
- Realistic physics (proper gravity and thresholds)
Step 4: Setting Up the Camera
Configure Main Camera
- Select the Main Camera in the Hierarchy
- In the Inspector, set these values:
Transform Settings
- Position: X: 0, Y: 0, Z: -10
- Rotation: X: 0, Y: 0, Z: 0
- Scale: X: 1, Y: 1, Z: 1
Camera Settings
- Projection: Orthographic (essential for 2D)
- Size: 5 (adjusts zoom level)
- Clear Flags: Solid Color
- Background: Light blue or your preferred color
Pro Tip: Camera Positioning
- Z: -10 keeps the camera in front of 2D objects
- Orthographic projection ensures no perspective distortion
- Size 5 provides a good view of your game world
Step 5: Configuring Project Settings
Quality Settings
- Go to Edit > Project Settings > Quality
- Select "Good" quality for 2D games
- Disable unnecessary features:
- Anti Aliasing: Disabled (2D games don't need it)
- Anisotropic Textures: Disabled
- Soft Particles: Disabled
Player Settings
- Go to Edit > Project Settings > Player
- Set these values:
- Default Screen Width: 1920
- Default Screen Height: 1080
- Fullscreen Mode: Windowed
- Resizable Window: Checked
Pro Tip: 2D Optimization
- Disable 3D features you won't use
- Use appropriate resolution for your target platform
- Windowed mode is great for development and testing
Step 6: Creating Your First Scene
Save the Default Scene
- Go to File > Save Scene As
- Navigate to your Scenes folder
- Name it "MainMenu"
- Click Save
Create a Basic Background
- Right-click in Hierarchy > 2D Object > Sprite
- Rename it to "Background"
- In the Inspector:
- Position: X: 0, Y: 0, Z: 0
- Scale: X: 20, Y: 15, Z: 1
- Color: Light blue or your preferred background color
Pro Tip: Scene Organization
- Save scenes frequently (Ctrl+S)
- Use descriptive names for scenes
- Create a background to establish your game's visual style
Step 7: Testing Your Setup
Play Mode Test
- Click the Play button in the top center
- You should see:
- A solid color background
- No errors in the Console
- Smooth 60 FPS performance
Console Check
- Open Window > General > Console
- Look for any red error messages
- Fix any issues before proceeding
Pro Tip: Regular Testing
- Test frequently during development
- Check the Console for errors
- Verify performance with the Stats panel
Common Setup Issues and Solutions
Issue: Camera Shows 3D Perspective
Solution: Ensure Projection is set to "Orthographic" and Position Z is -10
Issue: Physics Not Working
Solution: Check that Physics 2D settings are configured correctly
Issue: Poor Performance
Solution: Disable unnecessary Quality settings and use appropriate resolution
Issue: Sprites Look Blurry
Solution: Set sprite import settings to "Point (no filter)" for pixel art
Pro Tips for 2D Development
1. Use 2D-Specific Tools
- Sprite Editor for sprite animations
- 2D Physics for realistic movement
- Tilemap for level design
- 2D Lighting for atmospheric effects
2. Optimize for Performance
- Use sprite atlases to reduce draw calls
- Keep physics simple for better performance
- Use appropriate texture sizes for your target resolution
3. Plan Your Art Pipeline
- Decide on art style early (pixel art, hand-drawn, etc.)
- Set consistent sprite sizes for your characters and objects
- Use consistent color palettes for visual cohesion
Mini-Challenge: Create Your First 2D Scene
Task: Create a simple 2D scene with:
- A colored background
- A basic sprite object
- Proper camera setup
- No console errors
Time: 10 minutes
Success Criteria:
- Scene runs at 60 FPS
- No errors in Console
- Camera shows 2D orthographic view
- Background is visible and properly sized
Next Steps
Congratulations! You've successfully set up your Unity project for 2D development. Your project is now ready for the next phase of development.
What's Next?
In Lesson 3: Art Pipeline & Asset Creation, you'll learn how to:
- Set up an efficient art pipeline for 2D games
- Create and import sprites properly
- Design your main character and basic animations
- Organize your art assets for optimal performance
Key Takeaways
- Proper project setup is essential for 2D game development
- 2D-specific settings optimize performance and visuals
- Organized folder structure makes development more efficient
- Regular testing prevents issues from accumulating
Pro Tips for Success
- Save your project frequently to avoid losing work
- Test your setup before moving to the next lesson
- Keep your project organized as it grows
- Don't skip the mini-challenge - it reinforces what you've learned
Bookmark this lesson for quick reference - you'll need these setup steps for future 2D projects! Share your project setup with the community to get feedback and connect with other developers.
Ready for the next challenge? In Lesson 3, we'll dive into creating the visual foundation of your 2D platformer game!