Game Development Community

Interface not appearing

by rwillis · in Torque X 2D · 10/07/2007 (8:49 pm) · 1 replies

I went through the Airplane tutorial and interfaces worked fine for me there, but when I try to put an interface in a project I'm doing it doesn't appear. By "doesn't appear" I mean that when I put a debug message right after I call the GetInterface method I get absolutely nothing returned from my interface reference.

Here's the code in EnemyComponent:

protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;


            paused = Owner.Components.GetInterface<ValueInterface<bool>>("bool", "pause");
            
            Debug.WriteLine("paused =" + paused);

            ProcessList.Instance.AddTickCallback(Owner, this);

            return true;
        }

        ValueInterface<bool> paused;

The debug message I get back is "paused =". Here's the code in PlayerComponent where I declare the interface "InPlace":

protected override void _RegisterInterfaces(TorqueObject owner)
        {
            base._RegisterInterfaces(owner);

            Owner.RegisterCachedInterface("bool", "pause", this, paused);
        }

        ValueInPlaceInterface<bool> paused = new ValueInPlaceInterface<bool>(false);

It's seems weird to me that I don't get anything returned for my ValueInterface variable in the debug message. When I place a debug message at the exact same spot in the airplane tutorial I get "GarageGames.Torque.Core.ValueInPlaceInterface'1[System.Single]" back.

I have the PlayerComponent component on the player and EnemyComponent on the enemy. Anyone else get something like this before or know what may be happening? Thanks.

Edit: It looks like when I put both components on one object then I do get the correct debug message. So do both components accessing an interface value have to be on the same T2dSceneObject?

#1
10/07/2007 (10:06 pm)
Yes, generally interfaces are used by components on an object to interact with other components on that object. The GetInterface method looks up the interfaces that have been registered by the components on a particular object. (Although there's nothing actually preventing you from getting a reference to another object and using it's GetInterface method).