Search Unity

Unity.Engine.Debug:Error problem

Discussion in 'Scripting' started by ccronan, Jan 16, 2019.

  1. ccronan

    ccronan

    Joined:
    Jan 7, 2019
    Posts:
    3
    Can anyone explain what this means and/or how to fix? These assets are prefab lockers with combination locks I purchased on the asset store. The message I get on the console is "There is no locker component! Unity.Engine.Debug:Error problem (object)" Below is the script called LockerInteractor.cs. The problem seems to be almost at the very end. I've also attached the file. Thank you.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LockerInteractor : MonoBehaviour {
    5.  
    6.     public enum ActionID {
    7.  
    8.         None,
    9.         Lock,
    10.         Unlock,
    11.         Open,
    12.         Close,
    13.         SwitchOpenClose,
    14.         SetSymbol,
    15.         AddSymbol,
    16.         RemoveLastSymbol,
    17.         ClearAllSymbols,
    18.         ReassignControlSequence
    19.  
    20.     }
    21.  
    22.     [System.Serializable]
    23.     public class ActionParams {
    24.  
    25.         public ActionID id;
    26.         public char symbol;
    27.         public int symbolIndex;
    28.         public bool useEnteredSequence;
    29.         public string newSequence;
    30.         public AudioClip sound;
    31.  
    32.     }
    33.  
    34.     public Locker targetLocker {
    35.         get { return _targetLocker; }
    36.     }
    37.  
    38.     [SerializeField]
    39.     Locker _targetLocker;
    40.  
    41.     [SerializeField]
    42.     bool prewarmAction;
    43.  
    44.     [SerializeField]
    45.     protected ActionParams primaryAction;
    46.  
    47.     [SerializeField]
    48.     protected ActionParams secondaryAction;
    49.  
    50.     protected bool IsSymbolValid(char symbol) {
    51.  
    52.         return !char.IsWhiteSpace(symbol);
    53.  
    54.     }
    55.  
    56.     protected void Use(ActionParams action, bool playSound = true) {
    57.  
    58.         if (_targetLocker == null || action.id == ActionID.None) return;
    59.  
    60.         switch (action.id) {
    61.  
    62.             case ActionID.Unlock:
    63.  
    64.                 _targetLocker.Unlock();
    65.  
    66.                 break;
    67.  
    68.             case ActionID.Lock:
    69.  
    70.                 _targetLocker.Lock();
    71.  
    72.                 break;
    73.  
    74.             case ActionID.Open:
    75.  
    76.                 _targetLocker.Open();
    77.  
    78.                 break;
    79.  
    80.             case ActionID.Close:
    81.  
    82.                 _targetLocker.Close();
    83.  
    84.                 break;
    85.  
    86.             case ActionID.SwitchOpenClose:
    87.  
    88.                 _targetLocker.SwitchOpened();
    89.  
    90.                 break;
    91.  
    92.             case ActionID.SetSymbol:
    93.  
    94.                 _targetLocker.SetSymbol(action.symbol, action.symbolIndex);
    95.  
    96.                 break;
    97.        
    98.             case ActionID.AddSymbol:
    99.  
    100.                 if (IsSymbolValid(action.symbol)) {
    101.  
    102.                     _targetLocker.AddSymbol(action.symbol);
    103.  
    104.                 }
    105.  
    106.                 break;
    107.  
    108.             case ActionID.ClearAllSymbols:
    109.  
    110.                 _targetLocker.ClearCurrentSequence();
    111.  
    112.                 break;
    113.  
    114.             case ActionID.ReassignControlSequence:
    115.  
    116.                 if (action.useEnteredSequence) {
    117.  
    118.                     _targetLocker.LockWithEnteredSequence();
    119.  
    120.                 }
    121.                 else {
    122.  
    123.                     _targetLocker.Lock(action.newSequence);
    124.  
    125.                 }
    126.                
    127.                 break;
    128.  
    129.             case ActionID.RemoveLastSymbol:
    130.  
    131.                 _targetLocker.RemoveLastSymbol();
    132.  
    133.                 break;
    134.        
    135.         }
    136.  
    137.         if (playSound) {
    138.  
    139.             targetLocker.PlaySound(action.sound);
    140.  
    141.         }
    142.  
    143.     }
    144.  
    145.     public void Use(bool isSecondary = false) {
    146.  
    147.         if (isSecondary) {
    148.  
    149.             OnSecondaryAction();
    150.             Use(secondaryAction);
    151.  
    152.         }
    153.         else {
    154.  
    155.             OnPrimaryAction();
    156.             Use(primaryAction);
    157.  
    158.         }
    159.  
    160.     }
    161.  
    162.     protected virtual void OnPrimaryAction() { }
    163.  
    164.     protected virtual void OnSecondaryAction() { }
    165.  
    166.     protected virtual void Awake() {
    167.  
    168.         if (_targetLocker == null) {
    169.  
    170.             Locker lockerComp = gameObject.GetComponent<Locker>();
    171.  
    172.             if (lockerComp == null && transform.root != transform) {
    173.  
    174.                 lockerComp = transform.root.GetComponent<Locker>();
    175.  
    176.             }
    177.  
    178.             if (lockerComp == null) {
    179.  
    180.                 Debug.LogError("There is no Locker Component!");
    181.  
    182.             }
    183.  
    184.             _targetLocker = lockerComp;
    185.  
    186.         }
    187.  
    188.     }
    189.  
    190.     IEnumerator Start() {
    191.  
    192.         yield return null;
    193.  
    194.         if (prewarmAction) {
    195.  
    196.             Use(primaryAction, false);
    197.  
    198.         }
    199.  
    200.     }
    201.  
    202. }
     

    Attached Files:

    Last edited: Jan 16, 2019
  2. ccronan likes this.
  3. I guess if (lockerComp == null && transform.root != transform) this isn't solve to true, which means lockerComp will be null and the transform.root equal to transform. Which means you have this file on the root object?
    My advice is to ask the publisher what's up, they usually have some sort of support contact. Probably you made a set up mistake somewhere.
     
    ccronan likes this.
  4. ccronan

    ccronan

    Joined:
    Jan 7, 2019
    Posts:
    3
    Thank you very much. This helped a lot. Specifically, when you said I made a set up mistake, this helped me to try something new that fixed everything. I appreciate it!