- Home /
UI.Image Pixels Per Unit Multiplier doesn't update via code
Hello, I'm making a Neural Network modeling program, and I've already made a tiled Image for my background grid.
I'm trying to change Image Pixels per Unit Multiplier via code, which doesnt work (Editing it via editor in runtime works just fine)
Here's my code for Zoom In/Out:
float desiredSize = this.GetComponent<Camera>().orthographicSize;
desiredSize -= Input.mouseScrollDelta.y * 3;
//Clamp between min and max
desiredSize = Mathf.Clamp(desiredSize, minSize, maxSize);
//Smoothly interpolates to desired size
this.GetComponent<Camera>().orthographicSize = Mathf.Lerp(this.GetComponent<Camera>().orthographicSize, desiredSize, 5f * Time.deltaTime);
//Change pixels per unit multiplier to half of camera's size (with only 1 decimal char)
gridImage.pixelsPerUnitMultiplier = Mathf.Round( (this.GetComponent<Camera>().orthographicSize / 2) * 10f) / 10f;
It changes the value of pixels per unit just as intended, but it doesnt seems to have any effect on the Image itself.
Answer by hippogames · Jan 31, 2020 at 04:22 PM
Image.SetAllDirty(); will make it work but can produce random glitches later.
Your answer
Follow this Question
Related Questions
Canvas Scaler settings 0 Answers
Change size of UI canvas image, the best option? 1 Answer
World Space UI Scale To Fit Screen At DIfferent Aspect Ratios 1 Answer
Ui scaling 1 Answer