Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to create variants of custom objects #7403

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open

Allow to create variants of custom objects #7403

wants to merge 38 commits into from

Conversation

D8H
Copy link
Collaborator

@D8H D8H commented Feb 14, 2025

Changes

  • Custom objects can now have several inner scene tabs called variants.
    • For instance, you can design 2 buttons variants: one green, one yellow and use them across the game. When you change the label font of the yellow button variant, it will apply to every yellow button of the game.
  • Variants tabs don’t allow to add or remove objects, behaviors, group or variables. Changes must be done in the custom object inner scene tab that can be opened from the extension editor.
  • Assets from the store will be installed as variants. These variants can't be edited to avoid any loss downloading them again, but they can be duplicated to be edited.
  • A special property must be used in the extension editor to map text content from properties to child-objects. This will no longer be necessary when the 3D editor is released.

Known issues

  • Variants can't be renamed.
  • Variable cross renaming will result to instance variable value loss (in general, it's not specific to variants).
  • Variants can't be easily moved from one project to another
    • Variants are stored in extensions but they are not exported with the extension.
    • The events-based objects or the extension can be copy-pasted to another project, but resources need to be imported to the other project manually.
    • We could allow to import back GDO to solve this issue.

Demo

Require

@D8H D8H force-pushed the ebo-variant branch 2 times, most recently from c9fc931 to 5841389 Compare February 21, 2025 09:16
@D8H D8H force-pushed the ebo-variant branch 2 times, most recently from 16ff4ad to eccdb98 Compare February 28, 2025 18:10
@D8H D8H force-pushed the ebo-variant branch 7 times, most recently from ab9a9bf to 897e8ca Compare March 10, 2025 17:11
@D8H D8H marked this pull request as ready for review March 13, 2025 16:25
@D8H D8H requested a review from 4ian as a code owner March 13, 2025 16:25
@@ -8,7 +8,7 @@ const gd: libGDevelop = global.gd;
* and unserializeFrom method.
*
* @param {*} serializable
* @param {*} methodName The name of the serialization method. "unserializeFrom" by default
* @param {*} methodName The name of the serialization method. "serializeTo" by default
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth removing the comment and add a better typing of the argument. 'serializeTo' | ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do because we probably don't want (or will forget) to update the type when a new function is needed in Core. I guess it's fine to leave it as it is.

@@ -2196,6 +2254,7 @@ export default class SceneEditor extends React.Component<Props, State> {
hotReloadPreviewButtonProps={
this.props.hotReloadPreviewButtonProps
}
isListLocked={true}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm this is fine and that we don't need additional changes to unblock some authorised changes to the variables?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instance variable editor allows to reset back an instance variable to the default value. I guess it allows to remove undeclared instance variables.

There is probably something to do to help users understand why the "add" button is disabled and how they can add an object variable, but I guess this is already an improvement as it now forbids to add an undeclared instance variable which could be miss-understood as adding an object variable and sound like a bug when the events give no auto-completion for it.

return closeTabsExceptIf(state, editorTab => {
const editor = editorTab.editorRef;
if (editor instanceof CustomObjectEditorContainer) {
return (
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're sure about this predicate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variants tabs are CustomObjectEditorContainer with the variant name set (as they works mostly the same as the default variant tab).

@@ -2146,6 +2197,11 @@ export default class SceneEditor extends React.Component<Props, State> {
objectGroup
);
}
// TODO Set the `global` attribute correctly.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we either do this or not pass global: true/false at all if we don't know or if not useful?

const customObjectConfiguration = gd.asCustomObjectConfiguration(
object.getConfiguration()
);
if (customObjectConfiguration.getVariantName()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a risk we use default variant and so this is not detected?

Copy link
Collaborator Author

@D8H D8H Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, an empty name should be forbidden. I made it falls back on the asset name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants