Hi, I’m trying to instantiate a button and then set it as a child of the canvas. I have referenceResolution in my canvas in order to keep things properly scaled across different resolutions, and this works fine on gameobjects which are already in the canvas.
However, the instantiated button appears to not scale according to this resolution; instead, it looks very small on large resolutions, and very big on small resolutions. I suppose that setting it as the child of the canvas isn’t enough, and there’s something I’m missing here.
Here’s how I instantiate the button, levelMenu is the canvas that has referenceResolution:
Using transform.SetParent(targetParent, false) may help - I had all sorts of instantiate issues, I think there’s some internal data in the prefab trying to remember what it looked like the last time it was in the world, then tries to replicate that when instantiated. Using SetParent with false for the second parameter seems to tell it to not do that.
Note: I don’t think this default behavior is ever desirable, especially since one of the perks of this new GUI system is using anchors to get things to auto-conform to spaces
Then it will work fine. This is pretty annoying, because it means you have to make a prefab for everything you ever want to instantiate and add a component to it to do this. It would be nice if instantiate had a scale parameter to pass to it, or if this behavior was corrected.