2D Toolkit Forum

2D Toolkit => Support => Topic started by: R3nD on January 04, 2014, 01:39:47 pm

Title: Problem with attach point and sprite flipping
Post by: R3nD on January 04, 2014, 01:39:47 pm
Hi!
I've just bumped into a problem that I can't seem to figure out...
I have a sprite with several attach points. Some of them have stuff attached to them by design and other get attached stuffs on the fly. That's where my problem lies. When I instantiate a prefab and attach it to an attach point, then if I flip the parent sprite, I get the following error :

transform.position assign attempt for 'Player_goodtwin(Clone)' is not valid. Input position is { NaN, NaN, NaN }.

Player_goodtwin (which by the way is a prefab instance) is the parent object and its basic structure is the following :
Player_goodtwin->PlayerSprite(tk2dSprite)->JetpackLight(the attach point).

Here's the code when I attach the prefab instance to the attach point, quite straightforward :

Code: [Select]
Transform anchorPoint = transform.FindChild("PlayerSprite/JetpackLight");
Transform clone = (Transform) Instantiate(burstPrefab, anchorPoint.position+Vector3.back*0.02f, Quaternion.identity);
clone.parent = anchorPoint;

The prefab gets attached to the attach point, no problem. Besides, if I don't flip the parent sprite, no problem neither. The problem occurs only if I XFlip the sprite when the prefab instance is attached to it. It also occurs if I pause the game when the Burst prefab is instantiated and I flip manually the sprite through the Inspector.

When I flip my sprite with only game objects attached to attach points by design, I don't have any problem.


Any idea would be really appreciated  ;D

Thank's!
Title: Re: Problem with attach point and sprite flipping
Post by: unikronsoftware on January 04, 2014, 11:26:27 pm
I can't think of what would cause this, and  I can't seem to reproduce it here either. Can you create a simple repro case and email support, please?
Title: Re: Problem with attach point and sprite flipping
Post by: R3nD on January 06, 2014, 05:28:16 pm
Strangest thing... My BurstPrefab is an animated sprite and while I had deactivated the collider, some were still attached to the prefab.
So I deleted it manually and the bug disappeared.
I've generated a box collider again through the Sprite Editor, but I haven't been able to reproduce the bug.....

I guess the prefab wasn't in a clear state but now it's solved. Thank's again for having looked at it and sorry for the inconvenience!