Git Product home page Git Product logo

Comments (4)

sneakyevil avatar sneakyevil commented on August 20, 2024

You're supposed to pass il2cppObject as type not create new object, the game creates it for you.
The issue why GameObject::Find causes fps drop is based on the game and how many objects are in the scene, you should either cache the object ptr or itter through all objects and use hash name check or different approach to obtain the object.

from il2cpp_resolver.

svorogaze avatar svorogaze commented on August 20, 2024

Thank you for your answer! Could you please clarify what you mean by "You're supposed to pass il2cppObject as type"?

from il2cpp_resolver.

sneakyevil avatar sneakyevil commented on August 20, 2024

Thank you for your answer! Could you please clarify what you mean by "You're supposed to pass il2cppObject as type"?

AddComponent takes il2cppObject pointer and the argument is called "SystemType" so you will need to use this to get the type:

Unity::il2cppObject* GetSystemType(Unity::il2cppClass* m_pClass)

from il2cpp_resolver.

svorogaze avatar svorogaze commented on August 20, 2024

I rewrited my code, but now it always prints "component not found" even if I add it in the same update.

void ourmain() {
    static auto start = std::chrono::high_resolution_clock::now();
    auto cur = std::chrono::high_resolution_clock::now();
    if (std::chrono::duration<double, std::milli>(cur - start).count() > 1000) {
        start = cur;
        auto ptr = Unity::GameObject::Find("Default Camera");
        if (ptr) {
            Unity::il2cppClass* cptr = IL2CPP::Class::Find("UnityEngine.Light");
            if (cptr) {
                auto pt = ptr->GetComponent("UnityEngine.Light");
                if (!pt) {
                    ptr->AddComponent(IL2CPP::Class::GetSystemType(cptr));
                    pt = ptr->GetComponent("UnityEngine.Light");
                }
                if (pt) {
                    pt->SetPropertyValue("intensity", 1000.f);
                    std::cout << pt->GetPropertyValue<float>("intensity") << '\n';
                }
                else {
                    std::cout << "component not found\n";
                }
            }
        }
    }
    
}

EDIT:fixed by changing component name in getter from "UnityEngine.Light" to "Light"

from il2cpp_resolver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.