Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

First, I would like to say I apologize if this has already been asked and there is already an available thread covering this. I did my very best to try and find a resolution to this using preexisting resources, but nothing is really helping me.

Next the information I've been working from is here:

http://wiki.unity3d.com/index.php?title=Head_First_into_Unity_with_UnityScript#Virtual_functions_can_be_used_to_override_functions

It states that the virtual keyword is used to override functions/methods down the line if inherited from another object. More so it is my understanding that Unity automatically uses virtual key word unless otherwise specified.

So hypothetically with this train of thought in mind I would simply just pre-pend override in my function declaration and it should override it. However. That is not the case.

What occurs next is an error:

Assets/Scripts/Classes/Actors/TestPlayer.js(500,18): BCE0089: Type 'TestActor' already has a definition for 'getMovementVector()'.

Below are the class definitions shortened to just the initial skeleton and the functions I'm discussing.

class Actor extends DefaultGameObject {
    function getMovementVector() : Vector3 {
        var moveDirection = Vector3(0, 0, 0);

        if(isJumping && !jumpUsed) {

            //TODO: If double jump is added modify this line
            //so that the speed can be changed if you want that
            moveDirection.y += jumpSpeed;

            if(jumpTimer < jumpTimerMax) {
                jumpTimer++;
            }
            else {
                isJumping = false;
                jumpUsed = true;
                //animatedImage.animateOnceAndStopAtEnd(39, 39, 41);
            }
        }

        if((movingLeft || movingRight) && !(movingLeft && movingRight)) {
            if(movingLeft) {
                moveDirection.x -= moveSpeed;
            }
            if(movingRight) {
                moveDirection.x += moveSpeed;
            }
        }

        //applies gravity
        if(!isJumping) {
            moveDirection.y -= fallSpeed;
        }

        return moveDirection;
    }
}

Below is the code for the class that inherits from the above class with its function/method.

class TestActor extends Actor {
    override function getMovementVector() : Vector3 {
        var moveDirection = Vector3(0, 0, 0);

        if(isJumping && !jumpUsed) {
            if(doubleJumpUsed) {
                moveDirection.y += jumpSpeed;
            }
            else {
                //Debug.Log("omg jumping");
                moveDirection.y += jumpSpeed;
            }
            if(jumpTimer < jumpTimerMax) {
                jumpTimer++;
            }
            else {
                isJumping = false;
                jumpUsed = true;
                animatedImage.animateOnceAndStopAtEnd(39, 39, 41);
            }
        }

        if((movingLeft || movingRight) && !(movingLeft && movingRight)) {
            if(movingLeft) {
                moveDirection.x -= moveSpeed;
            }
            if(movingRight) {
                moveDirection.x += moveSpeed;
            }
        }

        //applies gravity
        if(!isJumping) {
            moveDirection.y -= fallSpeed;
        }
        return moveDirection;
    }
}

To me it seems relatively straightforward, but no matter what I do I cannot for the life of me get it to stop complaining about a method that has already been declared for it. I've tried explicitly using the virtual keyword as well. I tried adding access modifiers and that didn't change anything.

I would really appreciate any help or directions on where I can go for this. Thank you.

share|improve this question

closed as too localized by Josh Petrie, Tetrad Jan 4 '13 at 17:49

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Why not mark both to be virtual like in the example? –  Alex M. Jan 2 '13 at 1:35
    
I have tried that and it doesn't rectify it either. Also, I stated above that Unity implicitly adds the virtual keyword to variable declarations, so the implication is that they should both already have access modifiers of virtual with or without me explicitly adding it in. I also stated that above. –  GenericDeveloper Jan 2 '13 at 1:36
    
In Actor - virtual and in TestActor - override? –  Alex M. Jan 2 '13 at 1:39
    
Have you asked at the Unity Answers site? This question isn't off-topic here but the syntax is Unity-specific and there will be more people familiar with the issue there. (I would suggest dropping the override term, as it doesn't appear to exist in the docs there.) –  Kylotan Jan 2 '13 at 1:44
    
class Actor extends DefaultGameObject { That's JavaScript? –  jhocking Jan 2 '13 at 1:51

2 Answers 2

up vote 1 down vote accepted

Oh wow... This is embarrassing...

I'm just a big dope and didn't realize hidden in my file there was an empty method by the same name declared.

Thank you to all those who tried to answer this question. I appreciate the time and patience you all demonstrated.

share|improve this answer
    
Remember to accept your own answer so that this question register as properly solved. –  eBusiness Jan 2 '13 at 12:56

UnityScript doesn't use the override keyword. Use virtual instead.

http://wiki.unity3d.com/index.php/Head_First_into_Unity_with_UnityScript#Virtual_functions_can_be_used_to_override_functions

Edit: Looking your question over again, it seems you've already tried that. Are you sure you did it the way it shows at the link? I'm not sure why your code isn't complaining about the use of "override"; it's not even a keyword in UnityScript.

share|improve this answer
    
Yes, I am trying this in the same way that this is shown to me in the link. –  GenericDeveloper Jan 2 '13 at 4:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.