0 votes

I came across the built-in Reference type and as I understand it I think it would suit one of my needs. But I would like to check if I have understood it right. Here is my scenario:

I have a class InventoryItems (weapons, armor, etc) that are shown in various views (shops, drops, inventory, equipped inventory, etc). Items are always represented visually by an Item-scene which holds a reference to the InventoryItem. InventoyItems themselves are never in the scene-tree. Is this a good case to let InventoryItem inherit from Reference? The way I understand it is that if an InventoryItem is no longer used it will automatically be removed from memory and I would not have to free it myself like if it was an Object type.

Thank you!

in Engine by (49 points)

1 Answer

0 votes
Best answer

Yes, Reference is basically an Object for which you don't have to care about free(), otherwise you'll get memory leaks for a later one.

And yes, it's a good approach when you split entity into non-visual data structure (Object/Reference/Resource) and its visual representation (Node) in a scene tree.

by (1,438 points)
selected by

Great, thank you!

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 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 webmaster@godotengine.org with your username.