1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
1717using Unity . VisualScripting ;
18+ using UnityEngine ;
1819
1920namespace VisualPinball . Unity . VisualScripting . Editor
2021{
@@ -30,19 +31,20 @@ public static class GleUnitWidget
3031 public abstract class GleUnitWidget < TUnit > : UnitWidget < TUnit > where TUnit : Unit , IGleUnit
3132 {
3233 protected override NodeColorMix baseColor => GleAvailable ? GleUnitWidget . Color : NodeColor . Red ;
33- protected bool GameObjectAvailable => reference != null && reference . gameObject != null ;
34- protected IGamelogicEngine Gle => reference . gameObject . GetComponentInParent < IGamelogicEngine > ( ) ;
35- protected VisualScriptingGamelogicEngine VsGle => reference . gameObject . GetComponentInParent < VisualScriptingGamelogicEngine > ( ) ;
36- private bool GleAvailable => GameObjectAvailable && Gle != null ;
37- private bool VsGleAvailable => GameObjectAvailable && VsGle != null ;
34+ protected IGamelogicEngine Gle ;
35+ protected VisualScriptingGamelogicEngine VsGle ;
36+ protected bool GleAvailable => Gle != null ;
37+ protected bool VsGleAvailable => VsGle != null ;
3838
3939 protected GleUnitWidget ( FlowCanvas canvas , TUnit unit ) : base ( canvas , unit )
4040 {
41- if ( ! GameObjectAvailable ) {
42- unit . Errors . Add ( "Not attached to GameObject. You need to attach this graph to a flow machine sitting on a GameObject in order to use it." ) ;
43-
44- } else if ( ! GleAvailable ) {
45- unit . Errors . Add ( "No gamelogic engine found. One of the GameObject's parents must have a gamelogic engine component." ) ;
41+ var table = TableSelector . Instance . SelectedOrFirstTable ;
42+ if ( table != null ) {
43+ Gle = table . GetComponentInChildren < IGamelogicEngine > ( ) ;
44+ VsGle = table . GetComponentInChildren < VisualScriptingGamelogicEngine > ( ) ;
45+ }
46+ if ( ! GleAvailable ) {
47+ Debug . LogError ( $ "Cannot find GLE for { GetType ( ) } .") ;
4648 }
4749 }
4850 }
0 commit comments