Skip to main content

I’ve created a Figma plugin to get the state of local variables then trigger external API’s based on that state change.


I’m trying to have a prototype instance of the file communicate with the Figma Plugin I created so when I click a UI element in the prototype, a variable changes which triggers an external API. Right now, there’s no way I can find to ‘listen’ for the variable state change in a prototype because it does not ‘write’ to the original variable value.

Plugins cannot run in Presentation mode, and therefore receive changes from the prototype.


is this still the current behaviour? or can the plugin API already access the prototype variable values?


Hey @xiduzo, thanks for following up!


This is still the expected behavior. Plugins do not run in Presentation mode.


Hey ​@dvaliao, I think my last reply was taken away due to the migration to the new forum (love it by the way) and me not reading the huge banner on top. User never read right :p

Anyway, I was wondering if this is something which is being noticed as a actual bug?

I can see that plugins, like https://www.figma.com/community/plugin/1355055910166329140/variables-inspector, are using the https://www.figma.com/plugin-docs/api/properties/nodes-setboundvariable/ API to actually get updates from within the presentation mode.

This to me indicates that Figma has access to these variable changes from within the presentation mode, however slightly limited, and it would be wonderful for plugin developers to gain access to this as well!

I can imagine extending the current variable API with `.getPreviewVariablesAsync` similar to https://www.figma.com/plugin-docs/api/properties/figma-variables-getlocalvariablesasync/ or `.getPreviewVariableByIdAsync` like https://www.figma.com/plugin-docs/api/properties/figma-variables-getvariablebyidasync/.

Curious to hear your thoughts on this or any update regarding this issue!


Hi @xiduzo, thanks for replying again!

Yes - it does seem that your last reply was lost in the migration, but glad to hear you’re loving the changes. 😁


I took a look at your linked plugin, and yes - you can use a plugin in editor mode, so that your changes can/will appear in real-time to viewers of a presentation. That’s how the plugin you’ve linked is able to been seen in prototype mode. But keep in mind, there is still no way to run a plugin in presentation mode, so this is still expected behavior rather than a bug.

As shown in their YouTube demo, they run the plugin first in editor mode then switch to view the frame running the plugin in presentation mode. Again, you can’t “run” a plugin in a prototype itself, but you can always run them in a separate Figma edit window and still see it if set up to be visible within presentation mode. Hope this helps clarify! 



 


Thank you for your quick answer,

I think there might be some misunderstanding of what I am asking here.

I would like to know if it is possible to gain access to the variable values from the running preview mode. And if not, is there any feature plans to allow this in the (hopefully near) future?

I understand that, as of right now, you are not able to run the plugin directly inside of the preview mode, this is not what I am asking for.

However, I can see that the preview mode does react to changes of variables from the editor mode (your local variables) and the preview mode does have some way of updating values bound to variables (like the linked plugin is doing).

It does not make sense to me that my plugin, which runs from the editor mode, can affect variables in the preview mode by editing the local variables via the API but that same plugin does not have any access to see what are the values of that running preview.

For example;

I made a simple shopping cart page with some prototyping logic that calculates the amount of items the user has added to the cart (using variables) and based on the items price (using variables) I can calculate the total shopping cart amount (again, using variables). With all of this neat prototyping I can update the UI perfectly by linking text frames to the above mentioned variables.

Now, I would also be interested, from my plugin running in editor mode, to see the current state of the variables of the preview mode, not just of the local variables I have declared (which do not update from prototyping interactions).

I hope this clarifies the issue and I am looking forward to your response!


Cheers


Thanks for clarifying, ​@xiduzo

I’ll pass this onto our variables team for more input. I’ll follow up with an update, if this can be added to the future roadmap. 


hey ​@dvaliao, any update on this issue?

If you need any more input or clarification, do not hesitate to reach out to me!


Cheers


Reply