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

Mark component dirty in editor #17034

Open
ze0nni opened this issue May 23, 2024 · 4 comments
Open

Mark component dirty in editor #17034

ze0nni opened this issue May 23, 2024 · 4 comments
Assignees
Labels
Feature Request Needs Triage Needs to be assigned by the team

Comments

@ze0nni
Copy link

ze0nni commented May 23, 2024

Use Case

I am create component, who provides access to other compoent data.

Like this:

class MyBytton {
    @property(MyText)
    private _text: MyText;
    
    @property(CCString)
    get string(): string { retunr this._text.string; }
    set string(value: string) { this._text.string = value; }
}

Problem Description

This is work good in play mode.

I have problem in edit mode:
Then I change MyBytton.string in editor inspector, I see how text changed in MyText. But then I save prefab -- MyText нет saved.
I understand that I need to mark the component as "dirty" but I couldn't find how.

I saw there is a flag CCObject.Flags.Dirty and use it like this:

this._text.string = value;
this._text.node._objFlags |= CCObject.Flags.Dirty;
this._text._objFlags |= CCObject.Flags.Dirty;

But no result

Proposed Solution

No response

How it works

No response

Alternatives Considered

Avoid to complex components?

Additional Information

No response

@ze0nni ze0nni added Feature Request Needs Triage Needs to be assigned by the team labels May 23, 2024
@wuzhiming
Copy link
Contributor

When you change MyBytton.string and focus to another place editor will mark as dirty and the title will have change to xx.scene*

but if you want to know your text change event at inspector, you can use getter and setter as you provided and just add @executeInEditMode decorator

//add this decorator and this component will run on editor and you can use you setter and getter when on editor mode
@executeInEditMode
export class testComponent extends Component {
@property(MyText)
    private _text: MyText;
    
    @property(CCString)
    get string(): string { retunr this._text.string; }
    set string(value: string) { this._text.string = value; }
}

@ze0nni
Copy link
Author

ze0nni commented May 25, 2024

Tried create minimal project to reproduct bug. But No problem not reproduced.

I think the problem is in my project. This is what it looks like:
https://www.youtube.com/watch?v=vJX2dJir9M8

I will research problem more

@ze0nni ze0nni closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2024
@wuzhiming
Copy link
Contributor

wuzhiming commented May 25, 2024

or you can upload a simple demo and we will try this
https://www.youtube.com/watch?v=vJX2dJir9M8

@ze0nni ze0nni reopened this May 30, 2024
@ze0nni
Copy link
Author

ze0nni commented May 30, 2024

Success. This happens if you use prefabs

CocosTest.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Needs Triage Needs to be assigned by the team
Projects
None yet
Development

No branches or pull requests

2 participants