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

Entity.RemoveComponent(typeName, changeType) - ambiguous call of overloaded function #760

Open
Jarno-Poikonen opened this issue Mar 27, 2014 · 5 comments

Comments

@Jarno-Poikonen
Copy link

Only the component id overload works correctly. Passing in componen typename string with or without the component name is ambiguous. Same thing for the ComponentPtr overload, it seems to be confusing comp ptrs with strings. Possibly beacause IComponent.toString() is defined (eg. you can do print(ent.mesh);)

P.S. I am using the Meshmoon Rocket distro. Still needs to be verified if broken in the realXtend repo.

@Stinkfist0
Copy link
Contributor

Hmm, f.ex entity.RemoveComponent("Mesh") seems to work just fine for me using admino tundra HEAD. Also IComponent has no toString() function (like f.ex. Entity has) per se, but entity.mesh.toString() should use some QtScript's default QObject.toString() implementatioin.

entity.RemoveComponent(entity.mesh) will however produce the following, but that's ok as the syntax should be avoided in general:

Error: In run/evaluate: TypeError: ambiguous call of overloaded function RemoveComponent(); candidates were
    RemoveComponent(ComponentPtr)
    RemoveComponent(QString)

This can be worked around by using the usual (awkward) QtScript overload syntax:
entity["RemoveComponent(ComponentPtr)"](entity.mesh)

@jonnenauha
Copy link
Member

The toString() is added somewhere, you can afaik do print(ent.mesh); and its just works. So its there. Possibly in the QtScript expose code.

I think we should fix entity.RemoveComponent(ent.mesh). It should be safe to use as long as you dont use ent.mesh after the fact.

@Jarno-Poikonen
Copy link
Author

            // Creating a component for removal demostration
    function CreateDemoComponent()
    {
        var component = me.CreateComponent("Mesh", "cone", AttributeChange.Replicate, true);            
        return component;
    } 

    // Removal by component pointer
    var component = CreateDemoComponent();
    me.RemoveComponent(component);

    // Removal by type name
    component = CreateDemoComponent();
    me.RemoveComponent("Mesh", AttributeChange.Replicate);

    // Removal by type name and component name
    component = CreateDemoComponent();
    me.RemoveComponent("Mesh", "cone", AttributeChange.Replicate);      

    // Removal by component id
    component = CreateDemoComponent();
    me.RemoveComponentById(component.id, AttributeChange.Replicate);

    // Removal of all components        
    component = CreateDemoComponent();      
    me.RemoveAllComponents(AttributeChange.Replicate);

@Stinkfist0
Copy link
Contributor

In your example the first RemoveComponent will fail due to the overload issue already mentioned. Commenting that out, the second one will fail:

Error: In run/evaluate: TypeError: ambiguous call of overloaded function RemoveComponent(); candidates were
    RemoveComponent(QString,AttributeChange::Type)
    RemoveComponent(QString,QString)
    RemoveComponent(QString)
    RemoveComponent(ComponentPtr)
    RemoveComponent(ComponentPtr,AttributeChange::Type)

This would have been very useful information when submitting the original issue and would have helped to get to the bottom of this right away. I've edited the title to reflect the issue better.

To work around your issue for now use either of the following:

me.RemoveComponent("Mesh");
// or
me.RemoveComponent("Mesh", "", AttributeChange.Replicate);

Also note that me.RemoveAllComponents(); is not a smart move to be made from Script component of the me entity. ;)

@Stinkfist0 Stinkfist0 changed the title Enitity.RemoveComponent broken from script Entity.RemoveComponent(typeName, changeType) fails from script Mar 27, 2014
@Stinkfist0 Stinkfist0 changed the title Entity.RemoveComponent(typeName, changeType) fails from script Entity.RemoveComponent(typeName, changeType) - ambiguous call of overloaded function Mar 27, 2014
@jonnenauha
Copy link
Member

@Stinkfist0 Did you find out why this happens?

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

No branches or pull requests

3 participants