Author Topic: Weird Issue with Sprites (Urgent!)  (Read 10559 times)

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Weird Issue with Sprites (Urgent!)
« on: April 04, 2014, 06:23:06 PM »
I'm having an issue and bare with me due to the posting limit it is going to have 2 replies under it.  Please note all included pics are running the game is running in the editor as this is when the issue is occurring.

I have setup the scene to show the character with the UI like in the NGUI example X (ARGZ NGUI001 & ARGZ NGUI002).  and in the editor it appears as it should.  Yet it does not show up as it should in game (ARG NGUI 002).




PlayerObject is a persistent from the moment the game starts up, but the sprite attached is invisible until need and code shows it when the scene above is started and hides it when it ends.
« Last Edit: April 04, 2014, 06:29:52 PM by CoderBear »

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #1 on: April 04, 2014, 06:25:10 PM »
Now as a test I ran it and had the sprite manually and it appears without issue in the first two screens of the game as seen below (ARG NGUI004 & ARG NGUI005).

« Last Edit: April 04, 2014, 06:31:40 PM by CoderBear »

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #2 on: April 04, 2014, 06:27:36 PM »
However when we get to the third scene, the player sprite is not shown in the game, but it is showing up in the scene window.  (ARG NGUI006 & ARG NGUI007)

I really not sure what is happening exactly and at a loss to how to even approach it.

« Last Edit: April 04, 2014, 06:36:05 PM by CoderBear »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #3 on: April 04, 2014, 09:11:58 PM »
Don't hide your game view behind your scene view like that. When you do that, it's not possible to determine the size of the game view due to how Unity works.

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #4 on: April 05, 2014, 01:28:38 PM »
ok, if I had a much bigger screen I would do just that (Yet I don't have a 40" Monitor screen), but that doesn't really help the problem of why it is drawing in front in some scenes and not in others.

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #5 on: April 05, 2014, 02:02:14 PM »
Ok I did as you suggested but it did not solve the problem as seen below.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #6 on: April 06, 2014, 02:45:05 AM »
You realize that your sprite isn't using NGUI, right? "Sprite Renderer" is Unity 2D, not NGUI.

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #7 on: April 06, 2014, 12:48:42 PM »
Yes I am aware but that doesn't plain why it shows up perfectly in the Main Menu screen.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #8 on: April 06, 2014, 01:08:35 PM »
On the contrary. Many things are different between how NGUI draws things and how 2D sprites are drawn that affect the order in which things appear. It's difficult to mix NGUI drawing and 2D because you have to mess with render queues on panels and adjust the Z position of items to determine the order.

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #9 on: April 06, 2014, 02:35:19 PM »
Ok I tried and changed it to UI2Dsprite, but now it is drawing on the very bottom despite being the highest depth in the hierarchy. (Considering that you are using the painter's algorithm for rendering Bottom (0) -> Top (n))

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #10 on: April 06, 2014, 03:24:40 PM »
I think I see the problem.  The UI2Dsprite is being drawn and appearing under the camera in the hierarchy, but not under the panel.  Which is why it is being drawn behind everything.  At least I think that is the case.

Because I did a test with enemies that spawn and they also had the same issue until I dragged the object to under the panel and it suddenly appeared both in the editor and the game screen.  So I suppose the only question left is to how to make sure that happens with the player.  Unless since the player is a prefab for testing purposes in various scenes, if we do the same as with the follower it should in theory spawn appear in the same spot?

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #11 on: April 06, 2014, 04:23:25 PM »
Ok I figured out the problem.  If I spawn the mobs parented to the panel then they appear on the game screen.  Which leaves one last problem how to get the instantiated object to spawn in the correct spot.

The prefabs transform is (275,-75,0) and yet when it appears on screen the objects the Objects Transform is (0,0,0).  I even tried to change it after the fact and it doesn't do anything.

  1. NGUITools.AddChild (panel.gameObject, mobFollower);
  2. spawnedMobs.Add (GameObject.FindWithTag ("follower"));
  3. GameObject.FindWithTag ("follower").transform.position = MOB1_POS;

I even tried it using the translate function
  1. NGUITools.AddChild (panel.gameObject, mobFollower);
  2. spawnedMobs.Add (GameObject.FindWithTag ("follower"));
  3. GameObject.FindWithTag ("follower").transform.Translate (MOB1_POS)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #12 on: April 08, 2014, 12:11:13 AM »
NGUITools.AddChild resets the position to zero.

CoderBear

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Weird Issue with Sprites (Urgent!)
« Reply #13 on: April 08, 2014, 12:24:40 PM »
I noticed.  Also my other developer was having a similar issue.  Yet found out when spawning NGUI objects to use localPosition to changed position as opposed to using position (which is only used for NGUI objects already placed in the scene.