Forum rules - please read before posting.

Errors building with custom action script

Hi everyone!

I have a problem when I try to build a project that uses a custom
action.

I created the script following the "Writing a custom action" tutorial and
everything's works fine when I try the game in Unity, but when I compile the
project I get the following errors:




- error CS0115: `AC.ActionMyAnimation.ShowGUI()' is marked as an override
but no suitable method found to override;



- error CS0246: The type or namespace name `UnityEditor' could not be
found. Are you missing a using directive or an assembly reference?



It looks like it can't find the reference to UnityEditor, but I don't know
why...



The build settings are:



- target platform: windows;

- architecture: x86 (tried also x86_64 with the same result)

- development build: unchecked



Here's the code of the script:




using UnityEngine;

using System.Collections;

using UnityEditor;



namespace AC

{

[System.Serializable]

public class ActionMyAnimation :
Action

{



        // Declare variables here

        public Animator animator = null;



        public ActionMyAnimation()

{

this.isDisplayed = true;

            category = ActionCategory.Object;

            title = "My Animation";

            animator = new Animator();

        }



        public override void ShowGUI()

        {

            animator = (Animator)EditorGUILayout.ObjectField("Animator :",
animator, animator.GetType(), true, null);



            AfterRunningOption();

        }



        override public float Run ()

{

                  //do stuff

}

        }

}






Anyone knows why I get this problem?



Thanks!

Bye

Comments

  • I use Unity 5.3.1f1 Perosnal and AC 1.50g,
    thanks.
  • edited March 2016
    The ShowGUI() function requires UnityEditor's namespace, but the Action class itself cannot live in an Editor folder - meaning any reference to UnityEditor and it's API must live inside #if UNITY_EDITOR directives.

    This is an oversight with the tutorial, and I apologise - will update it with corrections.  In the meantime, you can see how these directives should be placed in your script by examining the "ActionTemplate.cs" example script.
  • Thank you Chris,
    solved, now it works.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!