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
1
Question by Alectora · Jan 11, 2014 at 03:30 AM · variablepackageimage-effectsaccessing from any script

How to modify variables from scripts in standard package?

Hi,

I have a main camera attached with lots of Image Effects, enabled from standard packages, such as CameraMotionBlur, SSAO, and Depth of Field to say a few.

My problem is, I cannot get the script objects (Ex.: GetComponent(DepthOfFieldScatter)), therefore I cannot modify their variables nor turning on/off the scripts.

However, it is completely fine with SSAOEffect. The fact that I found is, SSAOEffect script is a child of MonoBehaviour, while others' parent class is PostEffectsBase. If I have scripts or attach a script from the package with MonoBehaviour, yes it can be accessed normally.

Any idea?

Thanks.

EDIT: It might be very helpful if anyone who follow this thread could try on their own if they're willing to:

  • Use Unity Pro/Pro trial 4.x (4.3 to be exact)

  • Create a new project and add Image Effects (Pro only) package.

  • Add SSAOEffect (Add Component -> Image Effects -> Rendering -> Screen Space Ambient Occlusion)) and add DepthOfFieldScatter (Add Component -> Image Effects -> Camera -> Depth of Field (Lens Blur, Scatter, DX11)) to main camera.

  • Try to access both scripts in your own behavior script.

Comment
Add comment · Show 12
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 NutellaDaddy · Jan 11, 2014 at 04:33 AM 0
Share

Some components can't be changed within script if that's what you are trying to get at. I learned this when trying to mess with a halo component in script. Sorry.

avatar image Benproductions1 · Jan 11, 2014 at 08:33 AM 0
Share

The name in the menu does not have to be the same name of the class, make sure you're using the correct class name.

avatar image Alectora · Jan 11, 2014 at 09:19 AM 0
Share

@Benproductions1 Tried both and none works, it's the first thing I did.

avatar image Benproductions1 · Jan 11, 2014 at 10:03 AM 0
Share

Are you trying to access it from a higher compilation level or on the same compilation level from a different language?

avatar image Alectora · Jan 11, 2014 at 01:47 PM 0
Share

@Benproductions1 I don't understand what you mean by compilation level, but if you mean compatibility level, it's .NET 2.0 subset. What I know is I'm using C# and the scripts that are not working so far (like Camera$$anonymous$$otionBlur, DepthOfFieldScatter, etc.) are using .js. Could that be the problem? I also tried using my own .js file it still have the same limited access like when I use the C# one.

Show more comments

2 Replies

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

Answer by KellyThomas · Jan 12, 2014 at 03:49 PM

The scripts that you want to access are javascript, there are "issues" with manipulating them from c#.

I found that if I ran the following code:

 void Start () {
     Component[] components = GameObject.Find("Main Camera").GetComponents<Component>();
     foreach (Component c in components) {
         Debug.Log(c.GetType());
     }
 }

Then I received the following output:

alt text

So the components are real and accessible, with a type that can be recognised at runtime.

From here I see two options:

1) Reflection

We can use reflection to manipulate the component.

For example:

 using System.Reflection;

 // ....

 void Start () {
     Component dofs = GameObject.Find("Main Camera").GetComponent("DepthOfFieldScatter");
     FieldInfo fi = dofs.GetType().GetField("focalLength");
     fi.SetValue(dofs, 99.0f);
 }

2) SendMessage

We can use SendMessage() to call methods of the component. This is not immediately useful in this case but can be made to work by adding setters to the target scripts.

 void Start () {
     Component dofs = GameObject.Find("Main Camera").GetComponent("DepthOfFieldScatter");
     dofs.SendMessage("SetFocalLength", 99.0f)
 }    


output.png (6.8 kB)
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 Alectora · Jan 12, 2014 at 04:55 PM 0
Share

Well it's quite clear that I still have to use some tricks for the problem, but these are the best tricks so far. I'll check on both performance and see which I will use. Thanks.

avatar image
8

Answer by jemonsuarez · Mar 16, 2015 at 06:35 AM

There is an easy way:

 //C#
 using UnityStandardAssets.ImageEffects;

 //Javascript:
 import UnityStandardAssets.ImageEffects;

Then access the scripts normally (With object.GetComponent(Effect) )

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 Emery-Monzerol · May 11, 2015 at 10:25 PM 0
Share

$$anonymous$$uch better than reflection. Thanks a lot!

avatar image _invalidusername · Sep 07, 2015 at 08:36 PM 0
Share

Thank you! I knew it was something like this but it took forever to find it online

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

23 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

Related Questions

How to make two scripts share same variable? 1 Answer

enable disable variable of a script from another script 4 Answers

how to get other script variable from other scene? 3 Answers

how can I create a variable to refer to any gameObject script with pragma strict 1 Answer

Accessing another var on another script 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