Hi, I'm having a problem with the Subtitle Panel Offset (I'm using speech bubbles). Currently, I have a Playmaker FSM that turns the character in a top-down view in order to face the direction of an NPC.
The problem is, that means the speech bubble is always misaligned. I tried setting the Offset at runtime depending on the direction, but apparently it only sets the offset once at start and the position can't be changed again.
Looking at the script for Dialogue Actor, it pretty much confirmed my suspicions, with the function SetupDialoguePanels() only being run at Start. Can I make this function public so I could invoke it through the FSM? Or will that break the system?
Changing Subtitle Offset at Runtime
Re: Changing Subtitle Offset at Runtime
Hi,
Try using an Always Face Camera component. You may need to play with the settings to get it the way you want, such as ticking Rotate 180.
Try using an Always Face Camera component. You may need to play with the settings to get it the way you want, such as ticking Rotate 180.
Re: Changing Subtitle Offset at Runtime
Hi, thanks for the quick response!
Always Face Camera doesn't really seem to work here because my game is topdown with 2D graphics. That's why changing the Offset on the X axis would be ideal, at least from my viewpoint.
Would it be better to change the position of the bubble's parent object, then? Or is there some way I can change it in the Dialogue Actor itself?
Always Face Camera doesn't really seem to work here because my game is topdown with 2D graphics. That's why changing the Offset on the X axis would be ideal, at least from my viewpoint.
Would it be better to change the position of the bubble's parent object, then? Or is there some way I can change it in the Dialogue Actor itself?
Re: Changing Subtitle Offset at Runtime
Hi,
The Dialogue Actor's methods are virtual, so you can subclass it to change functionality. However, I don't think that's what you'll need to do for the bubble. Instead, add a script with an OnEnable() method to the bubble subtitle panel, or make a subclass of StandardUIMenuPanel if you prefer and override ShowSubtitle(). Either way is fine. In both cases, use the method to position the panel however you want.
For example -- and this is a rough, hypothetical example since I don't know the details of your character -- let's say you want to change the panel's local X position. It starts positive. If the character's SpriteRenderer.flipX is true, you want to set the X negative.
The Dialogue Actor's methods are virtual, so you can subclass it to change functionality. However, I don't think that's what you'll need to do for the bubble. Instead, add a script with an OnEnable() method to the bubble subtitle panel, or make a subclass of StandardUIMenuPanel if you prefer and override ShowSubtitle(). Either way is fine. In both cases, use the method to position the panel however you want.
For example -- and this is a rough, hypothetical example since I don't know the details of your character -- let's say you want to change the panel's local X position. It starts positive. If the character's SpriteRenderer.flipX is true, you want to set the X negative.
Code: Select all
void OnEnable()
{
// Runs on subtitle panel. Set local position x negative if sprite is flipped:
bool isFlipped = GetComponentInParent<SpriteRenderer>().flipX;
float localX = (isFlipped ? -1 : 1) * Mathf.Abs(transform.localPosition.x);
transform.localPosition = new Vector3(localX, transform.localPosition.y, transform.localPosition.z);
}
Re: Changing Subtitle Offset at Runtime
I did it! Had to adapt some of what you told me, but it worked out well!
This is basically what I did:
I basically check for the DialogueFSM, which only exists in the Player object, then use the functions inside that. This allows me to put the component in the bubble, which is used for all characters, but only performs this function for the Player.
For reference if anyone comes across this: the Turn bool is in my FSM and it's the result of a Conditional Expression that tells me the player's direction. And the localposition.x value can naturally be changed to a public variable if I need it for something else.
This is basically what I did:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ChangeBubblePlacement : MonoBehaviour
{
public PlayMakerFSM dialogueFSM;
void OnEnable()
{
dialogueFSM = PlayMakerFSM.FindFsmOnGameObject(transform.root.gameObject, "DialogueFSM");
if (dialogueFSM != null)
{
if (dialogueFSM.FsmVariables.GetFsmBool("Turn").Value == true) {
transform.localPosition = new Vector3(0.3f, transform.localPosition.y, transform.localPosition.z);
} else {
transform.localPosition = new Vector3(-0.3f, transform.localPosition.y, transform.localPosition.z);
}
}
}
void OnDisable()
{
transform.localPosition = new Vector3(0, transform.localPosition.y, transform.localPosition.z);
}
}
For reference if anyone comes across this: the Turn bool is in my FSM and it's the result of a Conditional Expression that tells me the player's direction. And the localposition.x value can naturally be changed to a public variable if I need it for something else.
Re: Changing Subtitle Offset at Runtime
Thanks for sharing your solution. That will be helpful to others in the future.