• 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
Question by Olly · Jan 12, 2016 at 09:35 PM · c#unity 5script.color

Accessing color presets in c# script.

I have many hex color presets that I'm tweaking in the game to get some nice effects. Thing is, lots of my particles relay on script that sets their colors. At the moment I have to store each of the presets as hex constants which is really inefficient.

My question, Can I access the presets in C# script? Something like Presets.RedPreset etc etc ?

Comment

People who like this

0 Show 0
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 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Ronnie_0 · Jan 03, 2018 at 12:24 AM

@Olly, looks like there is a class called ColorPresetLibrary, but it's not accessible via code. However, you can work around that by using a SerializedObject.

For this example, I have a color preset saved in my project at Assets/Editor/UI Colors.color.

 string colorPresetPath = "Assets/Editor/UI Colors.colors";
 UnityEngine.Object presetObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(colorPresetPath);
 SerializedObject so = new SerializedObject(presetObject);
 SerializedProperty presets = so.FindProperty("m_Presets");
 SerializedProperty firstElement= presets.GetArrayElementAtIndex(0);
 Debug.Log(firstElement.FindPropertyRelative("m_Color").colorValue);


Comment
dizzymediainc
podzimekpp

People who like this

2 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 dizzymediainc · Oct 03, 2020 at 05:28 AM 0
Share

Just found this while trying to access my custom Curve Preset Library and was able to use your method with a slight tweak to get it working, cheers!

             SerializedObject so = new SerializedObject(presetObject);
             
             SerializedProperty presets = so.FindProperty("m_Presets");
             SerializedProperty firstElement = presets.GetArrayElementAtIndex(0);
             SerializedProperty newCurve = firstElement.FindPropertyRelative("m_Curve");
 
             AnimationCurve curveSkirt = newCurve.animationCurveValue;

and then the usage:

newDynamBone.m_RadiusDistrib = curveSkirt;

The whole thing is pretty interesting, was previously trying to access values directly through the curve library but it stated the values were inaccessible, so serialization was the best method. With the animationCurveValue in SerializedProperty scripting docs makes that even more apparent.

But yea cheers again and will be playing with this more often :P

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Problem with "Using Unity Standard Assets" in script C# 1 Answer

How to change the color from code 1 Answer

My player keeps sliding after I use my dash, help! 0 Answers

How do I make the platform spawn after the other one 1 Answer

Unity 5 C#, having a script show up in a path in the Editor 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