Unity - Copy string to clipboard

Unity 2018 – How to copy a string to Clipboard

In Unity there is a cross-platform way to copy a string to Clipboard. Using the TextEditor class I’m going to show you how to copy a string into the user’s Clipboard. This should also work in Unity 2017 and Unity 5.

By using the TextEditor class, from UnityEngine, we can fit any C# object with a ToString() function into the Clipboard!

Clipboard Extension

To make it easily accessible I made the function as a string extension. By doing it this way we can use the function on any string anywhere in the code.

using UnityEngine;

public static class ClipboardExtension
    /// <summary>
    /// Puts the string into the Clipboard.
    /// </summary>
    /// <param name="str"></param>
    public static void CopyToClipboard(this string str)
        var textEditor = new TextEditor();
        textEditor.text = str;


Here is an example on how to copy different elements into the Clipboard using the ClipboardExtension:

public string GetSomeString()
    return "This is a string coming from a function!";

public void TestCopyToClipboard()
    // + Using a standard string
    string testString = "Am I in the Clipboard?";
    // The content of test1 is in the Clipboard now!

    // + Using a method to get a string
    // The content returned by GetSomeString() is in the Clipboard now!

    // + Using a C# object with a ToString() method
    Color colorTest = Color.red;
    // The string version of the object colorTest is in the clipboard now!

You can try out this code for yourself! Run it, then try pasting your Clipboard into a notepad. It has been tested and works on PC, WebGL and mobile!

Pierre Planeau

My name is Pierre and I run this website. You can learn more about me over here and some of my personal projects over there. 🙂

Other posts

  • COMMENTS (2)

    1. Avatar
      WilliamMew 27th May 2020 at 21:07 -
    2. Avatar
      Alexnuth 27th May 2020 at 20:45 -
    3. Avatar
      hercouriinpup 24th May 2020 at 21:06 -

      http://buycbdoilonline.us.com/ cbd oils [url=http://buycbdoilonline.us.com/ ]buy cbd [/url] medterra cbd

    4. Avatar
      Skjalg 26th September 2019 at 10:43 -

      This is just a long winded way of writing GUIUtility.systemCopyBuffer = text;

    5. Avatar
      17th September 2019 at 18:45 -



    Leave a Reply