Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by DrMonsieurMan · Nov 23, 2015 at 10:32 AM · c#editor-scriptingtrailrenderer

Problem with unity editor namesapce

Hello, I have a script that randomize the trail renderer colors each time I instantiate a new one. The problem is that the only way I can change the colors is via SerializedObject.

 public void RandomizeColor(TrailRenderer trailr)  {
             SerializedObject so = new SerializedObject(trailr);
     
             so.FindProperty("m_Colors.m_Color[0]").colorValue = new Color(Random.value, Random.value, Random.value, 1);
             so.FindProperty("m_Colors.m_Color[1]").colorValue = new Color(Random.value, Random.value, Random.value, 1);
             so.FindProperty("m_Colors.m_Color[2]").colorValue = new Color(Random.value, Random.value, Random.value, 1);
             so.FindProperty("m_Colors.m_Color[3]").colorValue = new Color(Random.value, Random.value, Random.value, 1);
             so.FindProperty("m_Colors.m_Color[4]").colorValue = new Color(Random.value, Random.value, Random.value, 1);
             so.ApplyModifiedProperties();
 } 

Then I use this method later on in the script. So it wprks but I can't build it as I'm using UnityEditor.

So my question is how do I work around that to be able to build the project.

Comment
Add comment
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
0

Answer by Jessespike · Nov 24, 2015 at 08:06 PM

Create a new separate script and move the Editor code to it.

Or if you want, you can wrap the Editor related stuff around preprocessors, this can get messy real quick though:

 using UnityEngine;
 using System.Collections;
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 
Comment
Add comment · Show 2 · 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 DrMonsieurMan · Nov 25, 2015 at 06:23 AM 1
Share

Ok, so if I use it as an editor script in a Editor file, how do I use it through this script after ? Because using preprocessors only makes it build but the intersting part doesn't run so there is not any point for mer.

avatar image Jessespike · Nov 25, 2015 at 08:48 AM 0
Share

Oops, I missed the part where you wanted to do this after an instantiate. Hmm, I'm not even sure if it's possible.

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

36 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 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

[Help][Noob] My Enums/Input won't work 1 Answer

How to Undo a lot of created objects at once? [Solved] 1 Answer

Access an Array of class inside another Array of class? (EditorGUILayout) 1 Answer

I want to use a variable in the Unity editor source file to get it from a regular script. 0 Answers

(Help) I am having trouble with creating a simple 2D game in Unity. Please help. :) 0 Answers


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