I’m wondering if this has to do with the way I am using these components…
First off, I have two of these Pixel Perfect Camera components attached to two different cameras. The reason I have two of them is because I needed a way to keep my UI pixel perfect, but also keep my game play pixel perfect.
I have a main camera and a UI camera. The UI camera only renders the UI, while the main camera renders everything else. The problem is, if I don’t have a pixel perfect component on the UI camera, I can’t keep the UI elements the same exact size proportions, depending on how I scale the main game play window. Therefore, I chose to use a Pixel Perfect Camera component, and set it to “WindowBox”. This keeps all my UI absolutely perfectly aligned and scaled just the way it should be when I scale my main game play window.
The issue is, this UI camera is an overlay to the main camera. When you stack one camera on top of the other, the Pixel Perfect Camera component displays a warning that it will not function correctly. So far, though, I haven’t run into any issues, except for trying to grab a reference to this component through code.
Here’s the component enabled -
Now, I grab a reference with this -
private void Awake()
{
_mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
}
private void Start()
{
_pixelPerfectCamera = _mainCamera.GetComponent<PixelPerfectCamera>();
}
I’m wondering if it has something to do with the fact that the Pixel Perfect Camera component is giving me this warning that it doesn’t function correctly, or if I am doing something wrong here.
EDIT: For clarity, These two are in different functions (Start and Awake) simple as an experiment to see if it was a timing issue, but that’s not the case. _pixelPerfectCamera
is still null regardless. I can’t make any sense of this, since the component is actually attached to the main camera game object, and is also enabled.