- Home /
Method to apply a UI Mask to Instantiated objects
I have a UI ScrollRect with a UI Mask script component attached to it. It is properly masking it's child elements which were created in the editor. Example: The ScrollRect contains a map image with child objects which are indicators of positions of importance on the map, such as the player's location. These are being moved by script and properly masked by the UI Mask script component.
PROBLEM: When adding map indicators at runtime via script, the added objects are NOT being masked by the UI Mask in the UI ScrollRect, even though they are parented to to the same objects and at the same level in the hierarchy as the working components.
How can I set an instantiated object to apply the UI Mask in it's parent?
Answer by Turlok · Jan 27, 2019 at 08:14 AM
Thank you @xxmariofer for the help, I've found the issue:
I was directly assigning the object's parent like this:
doorway.transform.parent = transform
rather than using the SetParent method:
doorway.transform.SetParent(transform, false);
Answer by xxmariofer · Jan 26, 2019 at 08:52 PM
i have never used this, but UI elements have a property call maskable that you can set to bool or false, can you try setting the myImage.maskable = true; when you instantiate it?
whats the prefab object you are usnig for instantiate? i have tested and i didnt need the maskable property since it was marked as true default but worked fine, so the problem must be other, try dragging the prefaba directly and check if it gets mask, if gets mask there must be something wrong with the parent.
Your answer
Follow this Question
Related Questions
How to see UI image (static) only trough specific UI element of the Scroll Rect? (Scroll View) 0 Answers
Check if visible in UI Mask 2 Answers
UI/Default stencil buffer for only parent? 0 Answers
Trouble with UI Mask 0 Answers
Disabling UI masks during runtime and changed material properties 1 Answer