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 - HHErebus

Pages: [1]
1
Support / Re: AnimationCompleteDelegate: Object reference not set
« on: January 20, 2014, 10:06:29 am »
Aaaaand, that solved it! Just FYI, I found the guide through google, I didn't even know about the new version  :P

Thanks a lot for your help, have a great day  :)

2
Support / Re: AnimationCompleteDelegate: Object reference not set
« on: January 19, 2014, 02:34:26 pm »
Thank you for your answer! I think I found what the problem is.

I followed your suggestion and set up a breakpoint: turns out _characterSprite is null because - you guessed it - there is no actual tk2dAnimatedSprite in my object, it's a tk2dSprite with an animator. I searched for the tk2dAnimatedSprite in the tk2d scripts and it's there, but it's marked as deprecated.

To set the animation up I was following your guide here, which uses that particular deprecated class, is there an "alternative" delegate that should be used for the same purpose in tk2dSprite? If not, could you give me a pointer regarding how to make the animation default to idle after attacking?

3
Support / AnimationCompleteDelegate: Object reference not set
« on: January 18, 2014, 10:20:55 pm »
Hey everyone!

I'm coding a simple animation system for an npc, but I'm having some problems with the animation complete delegate.

My code:
Code: [Select]
void Update(){

            // Is the character facing right?
            if (transform.position.x < _lastPosition.x){
                _facingRight = false;
            }
            else if (transform.position.x > _lastPosition.x)
            {
                _facingRight = true;
            }

            // Animate walk.
            if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0){
                _isWalking = true;
                if(!_characterAnimator.IsPlaying("Walk R") || !_characterAnimator.IsPlaying("Walk L")){
                    _characterAnimator.Play(_facingRight ? "Walk R" : "Walk L");
                    _weaponAnimator.Play(_facingRight ? "Idle R" : "Idle L");
                    _characterSprite.animationCompleteDelegate = null;
                }
            }

            // Animate attack.
            if (Input.GetButtonDown("Fast Attack") || Input.GetButtonDown("Strong Attack"))
            {
                if(!_characterAnimator.IsPlaying("Attack R" || !_characterAnimator.IsPlaying("Attack L")){
                    if (_facingRight){
                        _characterAnimator.Play("Attack R");
                        _weaponAnimator.Play("Attack R");
                    }
                    else if (!_facingRight){
                        _characterAnimator.Play("Attack L");
                        _weaponAnimator.Play("Attack L");
                    }
                    _characterSprite.animationCompleteDelegate = HitCompleteDelegate;                   
                }
            }
            _lastPosition = transform.position;
        }

        void HitCompleteDelegate(tk2dAnimatedSprite sprite, int clipId)
        {
               _characterAnimator.Play(_facingRight ? "Idle R" : "Idle L");
            _weaponAnimator.Play(_facingRight ? "Idle R" : "Idle L");
        }

Whenever I play the game, I get this error:
Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
Assets.Scripts.Game.Graphics.PlayerAnimation.Update () (at Assets/Scripts/Game/Graphics/PlayerAnimation.cs:85)

With the problematic line being
Code: [Select]
_characterSprite.animationCompleteDelegate = null;
It seems pretty simple to solve. Yet I've been at this for hours, and the solution still eludes me :/ Looking at the "Scripting an Animated Sprite" page, I don't understand what I'm doing wrong.

Any help will be appreciated, thank you very much :)

Pages: [1]