Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Snapshot Shaders Pro for Unity

A collection of 34 image effects for Unity URP, HDRP, and Built-in 路 By Daniel Ilett

How to change settings at runtime?

A topic by Dobertson created Jun 22, 2020 Views: 1,697 Replies: 2
Viewing posts 1 to 2
(1 edit)

Hey, firstly thanks for bundle, lot of really cool and useful shaders. I'm currently trying to simulate first person drunkness using the blur ones 馃榿

I'm using the URP, and I want to change the settings of the shaders via a script so I can change the strength and focal size of the radial blur at runtime. Would you know how to achieve this? 

I know you can set the render using 

Camera.main.GetComponent<UniversalAdditionalCameraData>().SetRenderer(index);  

but is it possible to manipulate the slider values at runtime?

Developer(+1)

Hi! That's a cool way of using the effects :)

Changing values at runtime on URP works something like this:

1) Get a reference to the Forward Renderer Data asset. The easiest way is to assign in the Inspector (this is the asset which contains all the Render Features):

public ForwardRendererData forwardRendererData;

2) Get the list of Render Features from that. It's a List<ScriptableRenderFeature>.

var features = forwardRendererData.rendererFeatures;

3) Iterate through the list and find the specific effect you want to modify. If you've only got, say, a Radial Blur effect applied, it's as easy as picking the first list element and casting to RadialBlur, for example:

RadialBlur blur = (RadialBlur)features[0];

If you've got a bunch of effects, you'll need to cycle through them all until you find the one you want.

4) Modify the property you want. Probably a good idea to do a null-check just in case. The settings variable is a struct which contains all the properties for a given effect - it's set up in the exact same way for every effect.

if (blur != null)
{
    blur.settings.strength = 27;
}

Please note, any changes you make in Play Mode using this approach will persist when you stop playing. I hope that helps! I'll be updating the documentation included in the asset pack to outline this process in the next major update.

(+1)

Just implemented this and it works a treat! Thanks a bunch mate 馃榿