Forum rules - please read before posting.

question about Custom Actions

I have made several stealth type scripts and I am converting them into Custom Actions. I have been successful but I have a question:

Where should I place in the script the assignment variables for instance I have the following:

    playerTarget = GameObject.FindGameObjectWithTag("Player");
    myRenderer = enemy.GetComponent<Renderer > ();
     anim = enemy.GetComponent<Animation > ();

either inside a Start() or Awake() or directly inside the public override float Run() ?

I noticed that inside Start() or Awake() they are not recognized only when I place them inside the Rum() what is the best procedure please?


Comments

  • Start and Awake functions have no effect, because Actions are derived from ScriptableObject, not MonoBehaviour.

    Placing in Run will be OK, but there is a dedicated AssignValues function that is called before this.  Just place your assign code in a function like:

    public override AssignValues ()
    {
      // Your code here
    }

    Most of AC's "official" Actions demonstrate this use.
  • it yields an error apparently it requires the return  so:

    public override void AssignValues

    works!!

    Yes I have seen this feature in other official Actions but not so clearly and simple as stated by you above.

    Thanks again . Perhaps the most salient point about your package is your unbelievable fast response to questions that users have this is rarely found with other suppliers of goodies !!


  • Thanks, you're welcome.  The Run function does require a return value of the time in seconds to re-run itself.  If it only needs to run once, you can just return 0f.
  • I give up. I have problems converting to Custom List and spent 8 hours on it.

    I wrote a script that checks distance between player and enemy and if DistanceB4Look is met then Enemy turns to LookAt player and if the distance is less than attack distance the enemy walks towards the player. It works like a charm when I attach the script to the enemy AI but  I cannot make it work the same way when I use the converted script to a Custom Action. Here is the script inside the Custom Action



    public override float Run()

            {

                PlayerDistance = Vector3.Distance (playerTarget.transform.position, enemy.transform.position);

                if (PlayerDistance < DistanceB4Look ) {

                    anim.CrossFade ("soldierWalk");

                    enemy.transform.position += enemy.transform.forward * enemySpeed * Time.deltaTime;

                }

                

                if (PlayerDistance < DistanceB4Attack) 

                {

                   quaternion .... typical and it works

                }

       

                return 0f;

            }

    where

    DistanceB4Look; // is set at 10f

     DistanceB4Attack; //
    is set at 7f

    When I ran it the soldier turns to look at player OK but when it starts to walk it does it in jerks like with a hiccup , it does advance though but of course is not normal.

    The cutscene just calls :

    Object: DetectsFollow (my created Custom Action) with parameters

     Engine:wait 1" and back to DetectFollow.




  • As you're returning 0f, the Action will only run Run() once whenever it is called in the ActionList.

    It looks like the code you want to run wants to be called every frame (hence the Time.deltaTime).  That kind of function is not appropriate for Actions.

    What are you trying to achieve, exactly, by converting your old script into an Action?  It might be better to simply use an Action to tell your old script to run.
  • You are right it was a case of hardheadedness from my part since the stand alone script is working fine. Now I know that there are restrictions in using Custom Actions such as you mention here.

    Most of the stealth situations I have used scripts such as laser fence, moving walls, turrets and this last one to check if the player can be seen.

    .... I will continue having fun which at my age is a big plus !!

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.