Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro How to strip rich text on clipboard copy (CTRL+C)?

Discussion in 'UGUI & TextMesh Pro' started by MrLucid72, Aug 16, 2021.

  1. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    962
    Let's say I have:

    `<style=foo>some styled text</style>`

    If I copy the chat and paste it somewhere, the result is an ugly unwrapped foo style:

    `<color=blue><size=80%>some styled text</size=80%></style>`

    How can I make it so that when a user copies the text, it copies just the raw text?

    `some styled text` // That's no longer styled upon copying, since style is useless outside of Unity and pasting styles elsewhere is likely unintended
     
  2. Joakim

    Joakim

    Joined:
    Dec 18, 2012
    Posts:
    5
    Hi MrLucid, I don't have the answer to your question but may I ask you how did you get "copy to clipboard" working?
    I have implemented a chat where each chat message is rendered through "TextMeshProUGUI" component. I want to select and copy text from my in-game chat into notepad for example. Do you know how could I do this?
    Currently, I cannot select any in-game chat text.
     
    MrLucid72 likes this.
  3. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    962
    GUIUtility.systemCopyBuffer = str;

    :) that's it. Good luck bud. I wish Unity docs were better - this one line took me hours to find.
     
  4. Iam01c

    Iam01c

    Joined:
    Nov 14, 2015
    Posts:
    3
    One solution for this is to create a TextMeshPro - Input Field and check Read Only in Control Settings.