The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hi guys.

I exported a variable called items in one of my scene that should keep track of an array of items in the game.

However, when I instanced the same scene, they all shared the same array. I would expect them to be unique for each instance.

My question is, how to make the say exported variable unique? Thanks in advanced.

Godot version latest
in Engine by (20 points)

1 Answer

0 votes

In the Scene panel of your editor: click the node that the script for items is attached to. Then go to the Inspector panel and click the little screw driver with the wrench icon near the top and press the Make Sub-Resources Unique option.

by (3,906 points)

This works, but it's very ugly. Exported arrays are always shared between all instances of the same node in godot. A better way would be to make your items child nodes of your parent node. This way you won't run into any issues when ever you want to change the code of your scene.

See the docs for more information on exporting arrays. Unfortunately, it's only mentioned in a comment in the example code. But I think this comment from Reddit summarizes it pretty well.

Exporting arrays works but with an important caveat: While regular
arrays are created local to every class instance, exported arrays are
shared between all instances. This means that editing them in one
instance will cause them to change in all other instances.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.