Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
10
Question by Baconaise · Jun 13, 2012 at 01:57 AM · uiguicopypaste

How can I add Copy/Paste clipboard support to my game?

I have the need to add Ctrl+C / Ctrl+V ( command for Mac) copy and paste functionality into my application. Ideally I could also create pop-up menus with right-clicks, but that could be addressed later so long as I have some way of getting clipboard content into the game.

In a .NET windows form application you can use System.Windows.Clipboard, but the System.Windows namespace is not available in Unity (perhaps not even Mono).

Does anyone else know if there's a way to do this? Thanks!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mizuho · Jun 13, 2012 at 02:00 AM 0
Share

http://forum.unity3d.com/threads/24101-Copy-TextField-or-TextArea-text-to-Clipboard

avatar image Baconaise · Jun 13, 2012 at 05:13 AM 0
Share

Yeah, I had found that thread. It had information but nothing actionable. I posted this question in hopes that someone had solved this.

6 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Baconaise · Jun 25, 2012 at 04:37 PM

It turns out you can do this using reflection to get at a private member of GUIUtility. I lost the link so I cannot site the project I found that did this, please add it if someone finds the original author:

 // C#
 // ClipboardHelper.cs
 using UnityEngine;
 using System;
 using System.Reflection;
 
 public class ClipboardHelper
 {
     private static PropertyInfo m_systemCopyBufferProperty = null;
     private static PropertyInfo GetSystemCopyBufferProperty()
     {
         if (m_systemCopyBufferProperty == null)
         {
             Type T = typeof(GUIUtility);
             m_systemCopyBufferProperty = T.GetProperty("systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic);
             if (m_systemCopyBufferProperty == null)
                 throw new Exception("Can't access internal member 'GUIUtility.systemCopyBuffer' it may have been removed / renamed");
         }
         return m_systemCopyBufferProperty;
     }
     public static string clipBoard
     {
         get 
         {
             PropertyInfo P = GetSystemCopyBufferProperty();
             return (string)P.GetValue(null,null);
         }
         set
         {
             PropertyInfo P = GetSystemCopyBufferProperty();
             P.SetValue(null,value,null);
         }
     }
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tabor · Oct 08, 2012 at 07:40 PM 0
Share

Hi, Baconaise

Could you expand on how to implement this?

avatar image GOMADWarrior · Dec 03, 2012 at 01:34 AM 0
Share

doesnt work on webplayer :S

avatar image Bunny83 · Jan 14, 2016 at 11:19 PM 3
Share

Uhm, i think i wrote that little helper ^^.

avatar image drudiverse · Oct 19, 2019 at 03:11 PM 0
Share

Returned an error in 5.3.3 , its irrelevant now too, demote it from best anser. just used myString = GUIUtility.systemCopyBuffer; was easier.

THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 - THE ABOVE CODE IS IRRELEVANT SINCE 2016 -

avatar image
15

Answer by Summit_Peak · Sep 14, 2015 at 01:48 PM

For Unity version 5.2.0f3, systemCopyBuffer is now a public member of GUIUtility:

   public static string Clipboard
   {
     get { return GUIUtility.systemCopyBuffer; }
     set { GUIUtility.systemCopyBuffer = value; }
   }




Comment
Add comment · Show 13 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image elenzil · Jan 04, 2016 at 06:12 PM 0
Share

in Unity 5.3.0 this is no longer public. I haven't confirmed if the previous 'reflection' approach works.

avatar image Diet-Chugg elenzil · Jan 14, 2016 at 10:54 PM 1
Share

the previous 'reflection' approach doesn't work in 5.3

avatar image elenzil Diet-Chugg · Jan 15, 2016 at 01:44 AM 1
Share

ugh, really ?

Show more comments
avatar image Jespertheend2 elenzil · Mar 25, 2016 at 08:18 PM 4
Share

it seems to be working again in 5.3.4

avatar image elenzil Jespertheend2 · Mar 25, 2016 at 08:36 PM 0
Share

sweet, thanks for the heads-up.

avatar image wmh49877 · Apr 25, 2016 at 04:56 AM 0
Share

thank you very much

avatar image siddharth3322 · Oct 05, 2016 at 03:19 PM 0
Share

Is this code work for iOS?? because in OSX its working but in iPhone its not working.

avatar image Jespertheend2 siddharth3322 · Oct 05, 2016 at 03:48 PM 0
Share

For iOS you'll need to write a plugin. Or you can buy one from the asset store. I usually make plugins myself since plugins from the asset store tend to not work well with other plugins. But it'll take a lot of time if you haven't done it before. I added iOS clipboard support a year ago and I totally forgot how to do it but I do remember it being a very tedious task.

avatar image siddharth3322 Jespertheend2 · Oct 05, 2016 at 04:00 PM 0
Share

@jespertheend2, thanks for your reply. Let see what other members say about this otherwise I purchase this plugin:

UniPasteBoard

Show more comments
avatar image NicoL3AS · Apr 26, 2019 at 03:37 PM 0
Share

Works great for me, thanks

avatar image
5

Answer by clintonb · Feb 24, 2016 at 05:50 PM

Here is a drop-in replacement for Baconaise's answer, using Summit_Peak's approach, that works in Unity 5.3.1p2 (and, hopefully, newer versions).

 // C#
 // ClipboardHelper.cs
 using UnityEngine;
 
 public class ClipboardHelper
 {
     public static string clipBoard
     {
         get 
         {
             return GUIUtility.systemCopyBuffer;
         }
         set
         {
             GUIUtility.systemCopyBuffer = value;
         }
     }
 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by onevcat · Jul 10, 2014 at 03:54 AM

The GUIUtility can work through the Unity itself, but if you want to use the system's clipboard (like on iOS or Android, you want to copy some text in your game and then paste it in other app), it won't help because the text is only in the GUI system of Unity.

I just posted a cross-platform plugin to solve this mess thing. It is using the system's clipboard to handle the copy&paste action. See it here in Asset Store, which could support iOS, Android, WP and some desktop platforms as well. It exposes the same API for all, and I hope it could make your life easier.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image naviln · Dec 19, 2019 at 09:55 PM 0
Share

Hi mate,

I coulnd't find your package on the Asset store anymore, but i found your github page. Are you still supporting the UniClipboard?

I posted an issue there, hoping you could have a look and give me a pointer on how to fix my iOS problem : https://github.com/sanukin39/UniClipboard/issues/7

avatar image
0

Answer by arutyunef · Jul 23, 2019 at 10:59 AM

Here is the slim version of clipboard property:

 public string ClipboardValue { get => GUIUtility.systemCopyBuffer; set => GUIUtility.systemCopyBuffer = value; }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Copy/Paste Key Combos in Webplayer 1 Answer

Use Unity UI For 2D Games Or Custom Objects Instead? 2 Answers

gameobject references runtime script in scene file 15 Answers

unity scrollview doesnt bounce 0 Answers

How to Make a Message Appear on Screen? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges