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

Initialize scene's object properties #165

Merged
merged 1 commit into from
Jun 20, 2022
Merged

Initialize scene's object properties #165

merged 1 commit into from
Jun 20, 2022

Conversation

lampysprites
Copy link
Contributor

Initialize scene traits after the objects are created, which makes child object lookup when assigning properties succeed. Solution from @MoritzBrueckner.

Initialize scene traits after the objects are created. Solution from @MoritzBrueckner.
@luboslenco
Copy link
Member

Thanks a lot!

which makes child object lookup when assigning properties succeed

Any example on when this happens? Is that not done via notifyOnInit()?

@lampysprites
Copy link
Contributor Author

lampysprites commented Jun 18, 2022

Sorry, I meant the lookup that happens internally, when initializing a property of a scene trait, whose type is Object. When set up like so, the property is null during and after initialization, not Cube:
blender_Q9JPaR8ikN

package arm;

class MyTrait extends iron.Trait {
    @prop var obj:iron.object.MeshObject;

    public function new() {
        super();
        notifyOnInit(() -> trace(obj != null)); // false
        notifyOnUpdate(() -> trace(obj != null)); // false false false ...
    }
}

Currently for scene traits, said lookup happens when Root is the only object in the scene as far as I can tell. It was this line IIRC.

Finding the object by name during onInit and assigning it to the property works as expected.

@MoritzBrueckner
Copy link
Contributor

To give a bit more background, previously the initialization order of a scene was the following:

create scene -> create scene traits -> spawn objects -> create object traits

Because of this, object properties weren't correctly initialized in scene traits, as @ lampysprites wrote.

With this change the new initialization order would look like this:

create scene -> spawn objects -> create scene traits -> create object traits

As a positive side effect we can probably remove the last paragraph in https://github.com/armory3d/armory/wiki/traits#trait-events, since it was only true for scene traits after #80 anyways. Now the onInit callback cannot be called anymore before all objects were created, this of course is also true for objects that are spawned later in the game.

@luboslenco luboslenco merged commit 9b90595 into armory3d:main Jun 20, 2022
@luboslenco
Copy link
Member

Awesome!

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.

3 participants