Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - pako

Pages: [1]
1
Support / Re: Animator.Play significant FPS drop on first call
« on: June 19, 2018, 04:12:05 pm »
As far as I can tell it's the sprite collection not being loaded. i.e. when the problem occurs the profiler shows tk2dSpriteCollectionData.Init() at 98.1%, whereas when there's no problem it's at 0%. Additionally, a break point after the return statement in tk2dSpriteCollectionData.Init() get's hit only when the problem occurs.

So, what would be the best way to deal with this issue?

2
Support / Animator.Play significant FPS drop on first call
« on: June 08, 2018, 02:57:03 pm »
Hi,

I have the following code:

protected tk2dSpriteAnimator Animator;

void Awake()
{
     Animator = GetComponent<tk2dSpriteAnimator>();
}

void MyMethod()
{
      Animator.Play(CurrentAnimationClipName);
}

Up to now, I've calling MyMethod() to set the Player's animation before the Player became visible, and there was no problem.

I recently added one more Player animation which gets set during gameplay (where CurrentAnimationClipName = Problem_AnimationClipName). In this case, the very first time that I call MyMethod() there is a significant FPS drop while the animation changes.  Visually, it's like the game freezes for a second and then the game continues normally. There's no problem in subsequent calls to MyMethod(). I used the Profiler to identify that the FPS spike is due to MyMethod().

I have found a temporary fix:

void Awake()
{
     Animator = GetComponent<tk2dSpriteAnimator>();

     Animator.Play(Problem_AnimationClipName);
     Animator.Stop(Problem_AnimationClipName);
}

This fix works because the correct clip gets sets after Awake(), and well, game freeze is not a problem any more.

Any ideas what could be causing this, and how I could fix it in a more elegant way?

Thank you in advance.

3
Support / Re: Advanced Collider Shapes Workflow
« on: October 10, 2017, 11:21:47 am »
Thank you!

4
Support / Re: Advanced Collider Shapes Workflow
« on: October 09, 2017, 06:56:49 pm »
Thank you for your prompt response.

Your script has been very helpful both for understanding how the system works, as well as to get me started on a full implementation.

It seems to me that for best performance I should turn this into an Editor script to create all colliders for a particular sprite in Edit mode, and then at runtime enable/disable the set of colliders corresponding to a particular animation frame.

As we are on this topic, could you please give some insight on the usage of the Input Box at the top of the Advanced Collider Editor. Apparently it's for the new naming feature, which was added in the last version of 2DTK.  It gets filled with strings, and you can select which one is active by clicking on the checkbox next to it.  What is the correct usage of this feature?

Thanking you in advance.

5
Support / Advanced Collider Shapes Workflow
« on: October 07, 2017, 08:19:07 pm »
Hi,

I want to use Advanced Collider Shapes, in order to have multiple colliders per sprite in a Collection that will be used for creating an Animated Sprite. So, as the Sprite animates and changes shape, the corresponding colliders will be enabled to approximate the sprite's shape in each animation frame.

I was able to create 4 Advanced Colliders per Sprite in the Collection by following the relative documentation: http://2dtoolkit.com/docs/latest/advanced/advanced_collider_shapes.html
but I haven't found any info in the documentation about the Advanced Collider Editor.  Also, it says that "At runtime, the collision shapes for a sprite can be obtained from the tk2dSprite.CurrentSprite.customColliders array." However, there are no examples on workflow and usage, and I really need some help on implementing this feature.

After I created the Animation from the Collection, I created a Sprite with Animator in the scene, and the added Sprite had a Polygon Collider, which I deleted, and I understand that I will have to add the colliders myself, but I don't know how to use the shapes that I created for each sprite in the Collections to help me add the correct shaped collider on the animated sprite.

I also don't know how to use the tk2dSprite.CurrentSprite.customColliders array to enable/disable the correct collider for each frame of the animation.

Your help will be very much appreciated.



6
Support / tk2d does not appear in in the Hierarchy Window
« on: December 30, 2015, 11:29:14 am »
This is probably related with an upgrade to Unity 4.7.

There is no tk2d submenu under the 2D Object submenu, after clicking Clicking the Create button in the in the Hierarchy Window.

Is there a quick fix for this?


UPDATE: Fixed it by adding UNITY_4_7 || at the beginning of the #if condition, in tk2dMenu.cs line 4.

7
Support / DefaultAsset does not exist error in Unity 4.7
« on: December 27, 2015, 09:45:04 am »
After I upgraded to Unity 4.7 I got a couple of errors "DefaultAsset does not exist" (attached snapshot of console).

I added: || UNITY_4_7  at the end of the #if condition, in lines 663 and 802 of tk2dSpriteCollectionEditorPopup.cs, and the errors went away.

However, I didn't look deep into this, and I don't know if this breaks anything.  So, is this fix OK?

Thanks

8
Support / Multiple Colliders get added on sprite automatically
« on: November 13, 2015, 07:24:14 pm »
Hello,

I'm using Unity 4.6.9f1, and the latest version of 2DToolkit.

I have a sprite animation and another single sprite in the scene.  The animation and single sprite belong to different collections, and they both have PolygonCollider2D attached inside the collection.  The sprite animation has a PolygonCollider2D for each sprite in the collection shaped according to each sprite.

Whenever I try to create a sprite in the scene, I get an error saying that the PolygonCollider2D has been destroyed but I'm still trying to access it (Error 2 attached).  Also when I click on the Play button, two things happen: a. I typically get a Null reference exception (Error 1 attached), and b. a new PolygonCollider2D gets added to both the animated sprite and the single sprite in the scene.  So, if I start and stop the Unity player 5 times, 5 extra polygon colliders get added to each sprite.  In other words, although the extra colliders get added at runtime, they are not removed when I stop the player.  Although my original "normal" colliders are set as triggers, the extra ones are not triggers.

Also, through a script I try to disable and then enable the polygon collider on the animated sprite. If the extra polygon collider gets added (usually), enabling/disabling of the original collider works properly.  However, there are some instances that the extra colliders don't get added, and then enabling/disabling of the original collider doesn't work.

Please tell me what might be wrong and how to fix it.

Thanks!

UPDATE:
I tried to reproduce these issues.  The 2 errors (attached snapshots) show up consistently.  However, the addition of multiple colliders does not happen consistently.  If I remove the problematic sprite instances and then recreate them, e.g. by dragging and dropping a prefab, colliders keep getting added every time I click on play.  However, this happens with the 2 specific prefabs, and not with others.  With other prefabs, if I remove the polygon collider, another one doesn't get added at all.

Additionally, the adding of extra colliders can start occurring without first removing the initial one.  It happened once, just after I had opened a collection, and then clicked play.  At that point, Unity hang, I had to restart it, and then colliders started adding up on the specific 2 instances.  However, I couldn't reproduce this.  I could reproduce with great probability Unity hanging after opening some (not all) of my collections, but not colliders being added after doing so.  So, I opened a "problematic" collection, clicked on Settings, and then clicked on one of the sprites in the collection, then clicked play, and Unity hang 90% of the time.

I'm really at a loss on what could be going wrong here, especially with colliders not properly acting like colliders.  I mean, I have an OnTriggerEnter2D event, the collider's "IsTrigger" is unchecked (gets unchecked by itself), but OnTriggerEnter2D still fires...

Obviously there's something seriously wrong with the setup, and if I hadn't spent many days setting it up, I'd just start from scratch, but that would mean losing many days (about 1-2 weeks actually) of work.

UPDATE 2:
I just discovered yet another way that multiple colliders get added.

First of all, I had tested the scene, and it seemed to behave more or less in a "stable" manner. Scene contents:
a. Player (animated sprite) with attached Rigidbody2D and PolygonCollider2D with IsTrigger enabled. Also attached a "Player" monobehaviour with OnTriggerEnter2D.
b. Power-Up GameObjects (single sprites) with only a  PolygonCollider2D and IsTrigger enabled (no Rigidbody2D attached).
c. A few Enemy GameObjects (animated sprite) that did not interact at all with the player in the present test.

When I clicked Play, OnTriggerEnter2D on the player fired only when it touched some of the Power-Up GameObjects, but not all of them, even though they are all set up the same.  However, there were no extra PolygonCollider2D added on any GameObjects.  This is why I say that it behaved more or less in a "stable" manner.

Then I thought that since OnTriggerEnter2D doesn't behave properly, maybe OnCollisionEnter2D will.  So, I commented out the OnTriggerEnter2D method and added a OnCollisionEnter2D method in the Player's Monobehaviour. I also disabled the IsTrigger on the player's collider.

I clicked Play and a PolygonCollider2D was added on every single GameObject in the scene that already had a collider on it.  Every time I stopped and then clicked Play again, an extra PolygonCollider2D was added on the affected GameObjects.

Additionally, OnCollisionEnter2D did not fire at all, when the Player went over the PowerUp GameObjects. I verified this, by placing a break-point inside the OnCollisionEnter2D method, and the break-point never got hit.

Interestinly enough, when the Player's collider was set as a trigger, the added extra colliders were NOT set as triggers, and when the Player's collider was NOT set as a trigger, the added extra colliders were set as triggers.

Here's the relevant code on the Player:

Code: [Select]
   
    //public void OnTriggerEnter2D(Collider2D other)
    //{
    //    if (other.tag == "PowerUp")
    //    {
    //        PowerUp newPowerUp = other.GetComponent<PowerUp>();
    //        StartCoroutine(ProcessPowerUp(newPowerUp));

    //        other.gameObject.SetActive(false);
    //    }

    //}

    public void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "PowerUp")
        {
            PowerUp newPowerUp = col.gameObject.GetComponent<PowerUp>();
            StartCoroutine(ProcessPowerUp(newPowerUp));

            col.gameObject.SetActive(false);
        }

    }

I also attach snapshots of the Inspector of the Player, PowerUp and Enemy GameObjects.

Some feedback and help would be really appreciated.

Pages: [1]