Search Unity

Question Lego Microgame - Why does SetActive(false) on triggerbrick, trigger the brick?

Discussion in 'Editor & General Support' started by bpiedlow, Mar 26, 2021.

  1. bpiedlow

    bpiedlow

    Joined:
    Aug 11, 2020
    Posts:
    6
    OK - so as quick explanation I created a game where you have to find bombs (pickups) and once found it would enable (SetActive=true) a detonator (trigger brick) so that you can trigger an explosion (explode brick).

    Using the scirpt listed below, I simply dropped the pickup-trigger/win block combo into the public triggerToEnable and the detonator's trigger brick into the public diabledBrick. When running in UnityEditor this would cause the detonator's trigger brick to simply disappear, then re-appear once the pickup-trigger's goal was met.

    Once compiled, when I open up the compiled game on my laptop or pc, as soon as the the detonator bricks vanish, they also set off their triggers - blowing everything up before you collect any bombs...

    Anyone know why and/or how to get around this problem so that the compiled game the disabled bricks are disabled but don't auto-trigger???

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.LEGO.Behaviours.Triggers;
    5.  
    6. public class BrickEnable : MonoBehaviour
    7. {
    8.  
    9.     public GameObject disabledBrick;
    10.     public GameObject triggerToEnable;
    11.     private PickupTrigger trigger;
    12.     private bool goal = false;
    13.  
    14.     void Start()
    15.     {
    16.         disabledBrick.SetActive(false);
    17.         trigger = triggerToEnable.GetComponentInChildren<PickupTrigger>();
    18.     }
    19.    
    20.     void Update()
    21.     {
    22.  
    23.         if (trigger.Progress >= trigger.Goal && !goal)
    24.         {
    25.             disabledBrick.SetActive(true);
    26.             goal = true;
    27.         }
    28.     }
    29. }
    30.  
     
  2. bpiedlow

    bpiedlow

    Joined:
    Aug 11, 2020
    Posts:
    6
    Still looking for any possible help on this. I have not found a work-around yet...
     
  3. bpiedlow

    bpiedlow

    Joined:
    Aug 11, 2020
    Posts:
    6
    Just as update to others whom might be trying to do same thing I did finally find a workaround for this today.

    Instead of disabling brick via SetActive, I added a public variable "reactivate" with default of false to the Lego Behaviour InputTrigger script. I then modified it's void Update() so that all code inside it was inside an if(reactivate) { }.

    Then I modified the code shown above to this instead:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.LEGO.Behaviours.Triggers;
    5.  
    6. public class BrickEnable : MonoBehaviour
    7. {
    8.  
    9.     public GameObject disabledBrick;
    10.     public GameObject triggerToEnable;
    11.     private PickupTrigger trigger;
    12.     private InputTrigger visable;
    13.     private bool goal = false;
    14.  
    15.     void Start()
    16.     {
    17.         //disabledBrick.SetActive(false);
    18.         trigger = triggerToEnable.GetComponentInChildren<PickupTrigger>();
    19.         visable = disabledBrick.GetComponentInChildren<InputTrigger>();
    20.     }
    21.    
    22.     void Update()
    23.     {
    24.  
    25.         if (trigger.Progress >= trigger.Goal && !goal)
    26.         {
    27.             //disabledBrick.SetActive(true);
    28.             visable.reactivated = true;
    29.             goal = true;
    30.         }
    31.     }
    32. }

    Problem solved
    Bert