Page 1 of 2

[SOLVED]Send Message OnConversation to Platformer Pro

Posted: Tue Apr 26, 2016 11:35 am
by OneManOnMars
Ok, this might be a tricky question. When Entering a conversation I want my player to stand still. I can not use the disable behaviour because it kills also gravity and therefore does not work. I am using Platformer Pro (PPro) as a control tool for all my movements and logic. What I do to bring my character to a halt is to send a message via the event responder to my Play_SpecialMovement gameobject.
For example, enter trigger > eventresponder sends message (PlayAnimation) to the gameobject. => Character Plays animation and is not controllable. Same for getting back controls (StopAnimation).
No I need to control this via dialog system!
I saw that there is the script Send Message on Dialogue Event.

But if I type in PlayAnimation it does nothing.

This is what happens if the messege is sent by PPro:
case EventResponseType.SEND_MESSSAGE:
action.targetGameObject.SendMessage(action.message, SendMessageOptions.DontRequireReceiver);
break;

Sorry, this might be a dumb question, but I just don't know much about stuff like that.

If anyone can help me or give me a hint into the right direction. This would be very much appreciated.

Re: Send Message OnConversation to Platformer Pro

Posted: Tue Apr 26, 2016 1:03 pm
by Tony Li
Hi,

There's a new Dialogue System Events component. (Menu item Component > Dialogue System > Miscellaneous > Dialogue System Events.) It didn't make it into the last documentation update.

The Dialogue System Events component is more convenient to set up than Send Message On Dialogue Event. Add it to your player, and then hook up your PPro methods to the On Conversation Start and On Conversation End Events. It works similarly to how you hook up events to UI buttons.

Re: Send Message OnConversation to Platformer Pro

Posted: Tue Apr 26, 2016 4:08 pm
by OneManOnMars
Thanks a lot. I didn't know about that. Right now I can't make it work, but I guess it is just due to me not knowing what to send. I will go trough the PPro documentation to see if I can find something.

Re: Send Message OnConversation to Platformer Pro

Posted: Tue Apr 26, 2016 8:50 pm
by Tony Li
I haven't used Platformer Pro, but if you're using standard input it looks like you can set StandardInput.enableController false to disable player control during conversations. Add a Dialogue System Events component to the Dialogue Manager and inspect it. Expand the Conversation Events foldout. Add events for On Conversation Start and On Conversation End. Assign the player's StandardInput component to both events, and select StandardInput.enableController. In On Conversation Start, leave the checkbox unticked. In On Conversation End, tick the checkbox so it re-enables input at the end of the conversation.

You might also want to use Character.SetVelocityX() and Character.SetVelocityY() to stop the character, which should put it in the idle state.

Please keep in mind that these are just educated guesses from skimming over the API reference, since I haven't actually used Platformer Pro myself.

Re: Send Message OnConversation to Platformer Pro

Posted: Sun May 01, 2016 9:56 am
by OneManOnMars
Thank you Tony for taking the time and aswering as detailed. Disabling the input like that does not work as far as I know. It exist a special movement type for exact that case and normaly it is triggered by the PPro event system via sending a message to that component (PlayAnimation) But I can not trigger that from the dialog system. If I send a message to that component I get this error:

SendMessage PlayAnimation has no receiver!
UnityEngine.Events.UnityEvent`1:Invoke(T0)
PixelCrushers.DialogueSystem.DialogueSystemEvents:OnConversationStart(Transform) (at Assets/Dialogue System/Scripts/Supplemental/Utility/DialogueSystemEvents.cs:118)
UnityEngine.Component:BroadcastMessage(String, Object, SendMessageOptions)
PixelCrushers.DialogueSystem.ConversationModel:InformParticipants(String, Boolean)

I can disable the character component. That works, but the problem is that deactivates the gravity as well, and like that I have no influence on what animation is played. It just plays the last played one over and over.

I have contacte the PPro Support with the same issue but I could not figure out how to get it working.

Here is the conversation:
http://platformerpro.boards.net/thread/ ... ollTo=1563

This is a bit tricky for me since I don't understand where the problem exactly is and I guess it is just a small thing, but I just can't figure it out.

Any further help would be very welcome!

Re: Send Message OnConversation to Platformer Pro

Posted: Sun May 01, 2016 10:07 am
by OneManOnMars
I just figured out that it is not true that the special movement_play animation is triggered via a send_message. A method is called from the event responder.

The Problem no is, that I can not call that method from the event responder of the dialogue system. I guess because I have to pass in an enum state to tell the method what animation as to be played. Not enirely sure if this is the problem. But from how I understand the PPro support this seems to be the case.

Any idea?

Re: Send Message OnConversation to Platformer Pro

Posted: Sun May 01, 2016 11:39 am
by Tony Li
This setup seems to work for me:

Image

I just added a Dialogue System Events component to the player and disabled Character.inputEnabled during conversations. (Make sure the player's GameObject is one of the conversation participants so it receives Dialogue System events.) If the player is running when the conversation starts, he comes to a stop. If the player is jumping when the conversation starts, he lands and then stops.

Will that work for you? If not, please let me know an example case that doesn't work, and I'll come up with a solution.

Re: Send Message OnConversation to Platformer Pro

Posted: Mon May 09, 2016 10:07 am
by OneManOnMars
Thank you for your help. But this does not work for my setup. The controls are connected closley to the character.
Talking to the support of PPro I need to call a method to get my character to be disconected from the controls and play a specific aniamtion.

Code: Select all

specialMovement  = character.GetComponentInChildren<SpecialMovement_PlayAnimation>();
if (specialMovement != null) 
{
	specialMovement.Play(action.animationState);
	break;
}
The thing is I have to pass trough the varables to define the animation state (IDLE) is there a possible solution for that?

Re: Send Message OnConversation to Platformer Pro

Posted: Mon May 09, 2016 3:19 pm
by Tony Li
Here are two options:

1. You could add a small script like this to your character:

ControlAnimation.cs

Code: Select all

using UnityEngine;
using PlatformerPro;

public class ControlAnimation : MonoBehaviour {

    public void PlayIdleAnimation() {
        specialMovement  = GetComponentInChildren<SpecialMovement_PlayAnimation>();
        if (specialMovement == null) {
            Debug.LogError("No SpecialMovement_PlayAnimation found on " + name, this);
        } else {
            specialMovement.Play(AnimationState.IDLE);
        }
    }
} 
Then add a Dialogue System Events component (similar to my previous post), add another line to On Conversation Start, and assign the ControlAnimation.PlayIdleAnimation method.


2. Or add this script to your character and omit the Dialogue System Events stuff:

IdleOnConversation.cs

Code: Select all

using UnityEngine;
using PlatformerPro;

public class IdleOnConversation : MonoBehaviour {

    public void OnConversationStart(Transform actor) {
        var character = GetComponentInChildren<Character>();
        if (character == null) {
            Debug.LogError("No Character found on " + name, this);
        } else {
            character.inputEnabled = false;
        }
        specialMovement  = GetComponentInChildren<SpecialMovement_PlayAnimation>();
        if (specialMovement == null) {
            Debug.LogError("No SpecialMovement_PlayAnimation found on " + name, this);
        } else {
            specialMovement.Play(AnimationState.IDLE);
        }
    }
    
    public void OnConversationEndTransform actor) {
        var character = GetComponentInChildren<Character>();
        if (character != null) character.inputEnabled = true;
    }
} 
In either case, your character should be assigned to the Conversation Trigger's Actor field. If you're triggering using OnUse, OnTriggerEnter, or OnCollisionEnter, and you've left the Actor field unassigned, it will automatically fill in the character when the trigger fires.

Re: Send Message OnConversation to Platformer Pro

Posted: Tue May 10, 2016 5:28 am
by OneManOnMars
Hi Tony,

thank you many many times! It works. Your answer was spot on I used the first approach with minor adjustments. Your help was more than I could have expected.

Ending the specialMovement ist rather simple. I just need to send a message.

THANK YOU! I had been working on this problem now for some time! I really have to write you guys a review in the asset store!!!