Problem with AbilityMessage

Henryos

New member
Hello!, I'm trying to display a message when the player can interact with a Door,

So I have my door script that is something like this:

Code:
public class hp_DoorMovement : MonoBehaviour, IInteractableTarget, IInteractableMessage
{   
    public bool CanInteract()
    {
        return true;
    }

    public void Interact()
    {
        Debug.Log("Interact!")
    }

    public string AbilityMessage()
    {
        return "Use Door";
    }
}

But the problem is that the message doesn't appear.

So I went to the Interact.cs script and changed this
Code:
public override string AbilityMessageText
        {
            get
            {
                var message = m_AbilityMessageText;
                if (m_Interactable != null) {
                    message = string.Format(message, m_Interactable.AbilityMessage());
                    Debug.Log(message);
                }
                return message;
            }
            set { base.AbilityMessageText = value; }
        }

for this:

Code:
public override string AbilityMessageText
        {
            get
            {
                if (m_Interactable != null) {
                    return m_Interactable.AbilityMessage();
               }
            }
            set { base.AbilityMessageText = value; }
        }

And now is working!!, but to be honest I don't want to change the source code of your asset to make it work.

So I wanted to know if this is a bug or there is something that I'm not getting about the working of AbilityMessage.

Thanks in advance!!
 
I'm kind of surprised that that worked - the get doesn't have a return value if m_Interactable is null so it shouldn't even compile.

The existing code uses string.Format so within the inspector of your interact ability make sure you specify where the interactable message should be located, such as the open door example:

PRESS F TO {0} DOOR
 
Sorry, I made a mistake when copying the code here.

The code that work is this:
Code:
public override string AbilityMessageText
        {
            get
            {
                var message = m_AbilityMessageText;
                if (m_Interactable != null) {
                    message =  m_Interactable.AbilityMessage();
                }
                return message;
            }
            set { base.AbilityMessageText = value; }
        }

I had to remove string.Format(message, m_Interactable.AbilityMessage()); because is clearing the message, and I don't know why.
 
See my message above - you need to make sure you mark where the interactable message should be located.
 
I got it! :D
Sorry, I was looking for some kind of reference to "where" should I display the message o something like that o_O. I was complete lost with your answer haha.
But now I get, I just had to put "{0}" in Ability Message Text(Interact Ability->UI) to display my own message.
Thank you for your patience!
 
Back
Top