# Get Opacity mask from material in C++?

**URL:** <https://forums.unrealengine.com/t/get-opacity-mask-from-material-in-c/374320>\
**Category:** Rendering\
**Tags:** canvas, opacity-mask, unreal-engine, question, CPP, UMG\
**Created:** [October 24, 2016, 4:29pm UTC](https://forums.unrealengine.com/t/get-opacity-mask-from-material-in-c/374320 "2016-10-24T16:29:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7b896cfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7b896cfc](https://forums.unrealengine.com/u/anonymous_user_7b896cfc)\
**Post date:** [October 24, 2016, 4:29pm UTC](https://forums.unrealengine.com/t/get-opacity-mask-from-material-in-c/374320/1 "2016-10-24T16:29:16Z")

</div>

Hello,

Is there a way to get the opacity mask used by a material from C++?  
I’m rendering on UPanelCanvas and I need to hide all of the UImage  
objects that are underneath the zero opacity area.

 ![112260-circularmask.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/9/2/3920fad4f67e6b1f11f38d5bd5704f4776c17d74.png)

So basically if I have a mask like the one illustrated above,  
everything within the white area shall be rendered and everything  
outside it, thus being in the black area shall not be rendered.

Am I missing something? Is there perhaps a better solution to it?

Thanks in advance.

P.S.: [forum link][2]

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [October 25, 2016, 1:47pm UTC](https://forums.unrealengine.com/t/get-opacity-mask-from-material-in-c/374320/2 "2016-10-25T13:47:27Z")

</div>

Hey Alisaxy-

The material class has an opacity mask variable that you can access publicly. If you have a material pointer, you can use this to get the opacity mask as necessary:

```
UMaterial* MyMaterial;
MyMaterial->OpacityMask;

```

Cheers

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7b896cfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7b896cfc](https://forums.unrealengine.com/u/anonymous_user_7b896cfc)\
**Post date:** [October 25, 2016, 5:26pm UTC](https://forums.unrealengine.com/t/get-opacity-mask-from-material-in-c/374320/3 "2016-10-25T17:26:12Z")

</div>

I’ve actually solved the problem without needing an opacity mask at all using UCanvasRenderTarget2D instead of UCanvasPanel. I imagine a need to mess around with FMaterialCompiler to get the data I need from the opacity mask and even then I wouldn’t be able to partially hide the panel slots outside the mask as it’s an all or nothing deal that way.

Nice to know still. 🙂 Thanks!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7b896cfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7b896cfc](https://forums.unrealengine.com/u/anonymous_user_7b896cfc)\
**Post date:** [October 25, 2016, 5:43pm UTC](https://forums.unrealengine.com/t/get-opacity-mask-from-material-in-c/374320/4 "2016-10-25T17:43:31Z")

</div>

Ah, found why I couldn’t find it myself. 😃 I was confused by UMaterialInstanceDynamic & UMaterial, they’re on different inheritance branches! I was always looking at the former, not the latter. Dang it! 🙂 Well, the best experience is gained from making mistakes. Dully noted!
