Forum rules - please read before posting.

Call event and Prefabs

Hi Chris, sorry to bother you during summertime,
I created a dissolve effect shader to show an image appearing or disappearing in GUI with a particulare fade in or fade out effect. Then I wrote a script to control the dissolving effect with a public function called StartDissolve with a bool argument (true fade in, false fade out) and I attached it as a component of the UI image.
When I call the function (i.e. StartDissolve) through the Object: Call Event checking or unchecking the bool it works fine.
But when I make the canvas a prefab and link it to an AC menu, it doesn't work anymore, neither with Call Event, nor with Send Message.
With the Object: Call Event it seems AC loses the object, not linking it to its constant ID (retain in prefab is checked and the element is turned on in the menu manager). While Call Event seems not to pass the bool to the function. Is there a way to do this inside AC ?
Thanks.

Comments

  • The Object: Call event Action relies on Unity's Event system, which requires a direct reference to the object - if you assign a prefab, it'll affect that prefab as opposed to the instance of it in the scene.

    Object: Send message can be used in this case, but you'll need to call a function with no parameters. You can update your script with such functions that call StartDissolve with the correct value, i.e.:

    public void FadeIn () => StartDissolve (true);
    public void FadeOut () => StartDissolve (false);
    

    You can then use the Action to invoke its FadeIn / FadeOut functions.

  • Thanks Chris, that's a cleaner solution. I tried to split the function into StartDissolve() and Startundissolve() and with SendMessage it actually works without bool. Your solution is more effective
    Thanks.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.