Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Tutorial] Creating an In-Game Level Editor within Unity 5

Discussion in 'Community Learning & Teaching' started by lparker, Jul 29, 2015.

  1. lparker

    lparker

    Joined:
    Apr 8, 2013
    Posts:
    30
    These are a set of tutorial's on building an in-game level editor inspired by the one in Timesplitters 2.

    It uses a modular level building approach and will cover a wide range of topics through out.

    Building an In game Level Editor. (Part #1)
    Building an In game Level Editor. (Part #2)
    Building an In game Level Editor. (Part #3)
    Building an In game Level Editor. (Part #4)
    Building an In game Level Editor. (Part #5)

    This post will be updated when new parts are added to the tutorial.

    Also if you have any comments or questions about the tutorial etc. Then feel free to ask :D
     
    Last edited: Aug 3, 2015
    EliasMasche and theANMATOR2b like this.
  2. JoakimCarlsson

    JoakimCarlsson

    Joined:
    Aug 27, 2014
    Posts:
    65
    Pretty sweet, going to bookmark this for later use.
     
  3. lparker

    lparker

    Joined:
    Apr 8, 2013
    Posts:
    30
    Thanks, I hope you enjoy it.
     
  4. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I ran into problems with part 3 of your tutorial. I got error messages after copying and pasting code from your website and Visual Studio IDE. You don't tell me where exactly to put the code. Where should I put these sections of code:

    public GameObject PartObject { get { return _partObject;}}
    private GameObject _partObject;

    public Vector3 PartLocation { get { return _partLocation;}}
    private Vector3 _partLocation;

    public string PartTag { get { return _partTag;}}
    private string _partTag;

    public bool IsSpawnPart { get { return _isSpawnPart;}}
    private bool _isSpawnPart;

    and

    public LevelPart(GameObject part, Vector3 location,string partTag, bool isSpawnPart){
    _partObject = part;
    _partLocation = location;
    _partTag = partTag;
    _isSpawnPart = isSpawnPart;
    }
     
  5. lparker

    lparker

    Joined:
    Apr 8, 2013
    Posts:
    30
    So with those two blocks of code they go between 'public class LevelPart{' and '} '

    So your code should look something like this:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace Entities{
    5.     public class LevelPart {
    6.         public GameObject PartObject { get { return _partObject;}}
    7.         private GameObject _partObject;
    8.  
    9.         public Vector3 PartLocation { get { return _partLocation;}}
    10.         private Vector3 _partLocation;
    11.  
    12.         public string PartTag { get { return _partTag;}}
    13.         private string _partTag;
    14.  
    15.         public bool IsSpawnPart { get { return _isSpawnPart;}}
    16.         private bool _isSpawnPart;
    17.  
    18.         public LevelPart(GameObject part, Vector3 location,string partTag, bool isSpawnPart){
    19.             _partObject = part;
    20.             _partLocation = location;
    21.             _partTag = partTag;
    22.             _isSpawnPart = isSpawnPart;
    23.         }
    24.     }
    25. }
    Out of curiosity what kind of error are you getting?

    Hope this helps :)
     
  6. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I got phrasing error messages because I didn't know where exactly should I put pieces of code.
     
  7. lparker

    lparker

    Joined:
    Apr 8, 2013
    Posts:
    30
    Ahh ok, is it working now?
     
  8. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    I got another error message:
    Error 1 The name '_levelPartClone' does not exist in the current context C:\Users\jeffrey\Documents\Unity Projects\level-editor\Assets\Scripts\LevelManager.cs 43 9 Assembly-CSharp-vs
     
  9. lparker

    lparker

    Joined:
    Apr 8, 2013
    Posts:
    30
    Just noticed the code had been changed a bit on my version, just not on the website :D

    That error is because the '_levelPartClone' wasn't being declared as a variable anywhere in the code. Totally my bad :)

    I've updated the code on the website and the code you need for it to work is below :D

    Code (CSharp):
    1. private LevelPart PlaceObject(GameObject part, Vector3 location){
    2.         var newTag = GenerateGuid ();
    3.         GameObject _levelPartClone = GameObject.Instantiate(part,location,part.transform.rotation) as GameObject;
    4.         _levelPartClone.name = newTag;
    5.  
    6.         return new LevelPart(_levelPartClone,location,_levelPartClone.name,false);
    7. }
    Thanks for bringing this up.
     
  10. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    276
    Please check Part 4 of your tutorial. I can't rotate the objects.
     
  11. lparker

    lparker

    Joined:
    Apr 8, 2013
    Posts:
    30
    So if you look at the code you have so far for the rotation inputs (Should look like this):
    Code (CSharp):
    1. if(Input.GetButtonUp ("RotateLeft")){
    2.     var newTransform = _levelManager.RotateLeft (_partList.SelectedPart.transform);
    3.     _partList.SelectedPart.transform.rotation = newTransform.rotation;
    4. }
    5. else if(Input.GetButtonUp ("RotateRight")){
    6.     var newTransform = _levelManager.RotateRight (_partList.SelectedPart.transform);
    7.     _partList.SelectedPart.transform.rotation = newTransform.rotation;
    8. }
    Then you should see that currently this code sets the rotation for the SelectedPart which is what is being placed.

    For the moment it doesn't rotate what is already placed, but what is set to be placed.

    Though in later tutorials there will be a visual indicator made to show what the current rotation is.

    I hope this helps.