playMaker

Author Topic: Call Method action executing before Start method in script?  (Read 917 times)

Guardoro

  • Playmaker Newbie
  • *
  • Posts: 1
Call Method action executing before Start method in script?
« on: September 26, 2019, 02:44:04 PM »
New PlayMaker user here; relatively experienced Unity and C# user. I've been testing out the Call Method action and have been having the bizarre experience of seeing Call Method actually take effect before the Start method of the same script.

Here's my (greatly simplified) code:

Code: [Select]

Transform player = null;

private void Start()
{
    player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}

public override void CheckSensor()
{
    Vector3 difference = player.position - transform.position;
    <do other stuff>
}

Call Method is, of course, calling the CheckSensor method of the script. I've been able to confirm by adding print statements that CheckSensor is executing before Start, leading to the "player" variable having a value of null when it runs. Am I interpreting this correctly? Does the Call Method action actually execute earlier in the first frame of the game than Start does?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Call Method action executing before Start method in script?
« Reply #1 on: November 13, 2019, 03:07:36 AM »
Hi,

 it's likely due to the script order of execution, if you want to do something before start, do that in Awake().

the other way is to make a small method to get the player, and there you check if player is null and if null, you get it, this way it will find the player the very first time it needs it and not during the initial phase of script execution.

Bye,

 Jean