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 /
avatar image
0
Question by Old-Meiser-Gaff · Jul 29, 2019 at 08:58 PM · camerapost processingpost-process-effectfocusdepth of field

How to change Focus Distance at run time? Using PostProcessing Depth of Field.

EDIT: Good news everyone! I figured out what I was doing wrong. Simply... I just was referencing the wrong PostProcessingVolume. I was referencing the one on my camera, and there already was a GameObject in the scene with a PostProcessingVolume on it. Referencing that one with my same code works like a charm. I feel like an idiot. Haha! Happy coding all. :) -Gaff

Hi I'm using Unity 2019.1.1f1 and the LWRP.

I want to change the Focus Distance of the Depth of Field Effect using Post Processing.

I've read all of the numerous posts on here and still don't have an answer.

With the following code and a properly setup Profile on a PostProcessingVolume on my camera I can get the Focus Distance to update and change in the inspector properly during run time, but the actual depth of field does not change from it's original setting when the game began?

 [SerializeField]
 private PostProcessVolume postProcessVolume;
 [SerializeField]
 private DepthOfField DOF; 

 void Awake ()
 {
     postProcessVolume = camera.gameObject.GetComponent<PostProcessVolume>();
     postProcessVolume.profile.TryGetSettings(out DOF);
 }

 void Update ()
 {
     RaycastHit hitInfo;
     Ray rayDOF = new Ray(camera.transform.position, camera.transform.forward);
     
     if (Physics.Raycast(rayDOF, out hitInfo))
     {
         FloatParameter newFocusDistance = new FloatParameter { value = Vector3.Distance(camera.transform.position, hitInfo.point) };
     
         DOF.enabled.value = true;
         DOF.focusDistance.value = newFocusDistance;
     }
     else
     {
         DOF.enabled.value = true;
         DOF.focusDistance.value = 200f;
     }
 }


Do I have to apply this effect after making changes? Is there some method to call?

What am I missing here?

I've searched everywhere and can't find the answer. Thanks all! :)

Gaff

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
Best Answer

Answer by Old-Meiser-Gaff · Aug 03, 2019 at 03:12 AM

EDIT: Good news everyone! I figured out what I was doing wrong. Simply... I just was referencing the wrong PostProcessingVolume. I was referencing the one on my camera, and there already was a GameObject in the scene with a PostProcessingVolume on it. Referencing that one with my same code works like a charm. I feel like an idiot. Haha! Happy coding all. :) -Gaff

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

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

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

make your camera see through an Image!! 2 Answers

Get Camera Current Post Profile Name 0 Answers

How to change the color of a vignette? 0 Answers

Modify values on VolumeProfile URP. 1 Answer

Capture Screen with post effect 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