Author Topic: NGUI Reference Atlas  (Read 9150 times)

ghoulfool

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
NGUI Reference Atlas
« on: January 30, 2014, 10:44:11 AM »
I've been following the video about NGUI: Reference Atlas http://www.youtube.com/watch?v=dbwgP6PC4go

I've emulated the scene as far as I can see using the following LoadAtlas script

  1. using UnityEngine;
  2.  
  3. public class LoadAtlas : MonoBehaviour
  4. {
  5.    public UIAtlas referenceAtlas;
  6.    public string sdAtlas = "SD";
  7.    public string hdAtlas = "HD";
  8.    public bool loadHD = true;
  9.  
  10.    void Awake ()
  11.    {
  12.       GameObject go = Resources.Load(loadHD ? hdAtlas : sdAtlas, typeof(GameObject)) as GameObject;
  13.       referenceAtlas.replacement = go.GetComponent<UIAtlas>();
  14.    }
  15. }
  16.  


However the script is barfing  at the last line.

  • Null Reference Exception: Object reference not set to an instance of LoadAtlas.Awake() (at Assets/classes/LoadAtlas.cs:13)
I can't think what it can be referring to. I've linked the script to the UI root and the Reference Atlas vaiable in said script to refAtlas - which is my reference atlas
Any ideas??

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Reference Atlas
« Reply #1 on: January 30, 2014, 12:13:41 PM »
It means "go" is null, implying it failed to load your atlas.

You need to ensure that the atlas prefab is in your Resources folder.

ghoulfool

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: NGUI Reference Atlas
« Reply #2 on: January 31, 2014, 09:44:30 AM »
In your video you already have the reference atlas in the scene. (Which kind of defeats the purpose of explaining how to use to use them if you don't know how to create a prefab reference atlas)

So, since the atlases are already in the projects folder, how do you make a prefab (reference) atlas then?
Simply duplicating an existing atlas and then changing the Atlas Type to reference doesn't seem to work. As soon as you click back on the newly duplicated atlas, it's Atlas Type reverts back to Normal instead of Reference. Frustrating! :o

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Reference Atlas
« Reply #3 on: January 31, 2014, 10:10:30 AM »
To create an empty atlas, create a game object (ALT+SHIFT+N) and attach UIAtlas script to it. Save it as a prefab by dragging it into your Project view.

ghoulfool

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: NGUI Reference Atlas
« Reply #4 on: January 31, 2014, 11:19:57 AM »
... which brings us back to square 1. Null Reference Exception.  >:(


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Reference Atlas
« Reply #5 on: January 31, 2014, 11:27:50 AM »
Check what's actually 'null'. If it's 'go' then you likely didn't place the atlas prefab in the proper place (Resources folder).

ghoulfool

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: NGUI Reference Atlas
« Reply #6 on: January 31, 2014, 11:34:38 AM »
The reference Atlas in the same folder as the other Atlases (Atlesi??) which is in the Assets folder.

I might need to be walked through this with a tutorial as I've lost nearly two days on this and am getting nowhere fast.
« Last Edit: January 31, 2014, 11:59:33 AM by ghoulfool »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Reference Atlas
« Reply #7 on: January 31, 2014, 12:13:02 PM »
Look closely at the project window hierarchy in the video. Atlases are located in the "Resources" folder.

Unity cannot load things from anywhere other than the Resources folder when doing Resources.Load.

ghoulfool

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: NGUI Reference Atlas
« Reply #8 on: February 05, 2014, 05:09:28 AM »
Thanks, I got it to work in the end. Differentiating between "Assets" and "Resources" without explicitly saying say so can be a bit confusing to the uninitiated.