Giter VIP home page Giter VIP logo

Comments (1)

ozbao avatar ozbao commented on August 28, 2024

在 Unreal Engine 的 Lua 脚本中,你在代码中看到的 self.RTGMesh:SetAnimClass(ABP_Lin_Class) 和 self.RTGMesh.SetAnimClass(ABP_Lin_Class) 这两种写法有不同的含义。

self.RTGMesh:SetAnimClass(ABP_Lin_Class):这种写法使用了 : 符号,表示这是一个方法调用。在 Unreal Engine 的 Lua 脚本中,当你使用 : 来调用一个方法时,Lua 会自动传递对象本身作为第一个参数(类似于 self 指针),这样方法就可以在内部访问对象的成员和方法。SetAnimClass 方法在这里会被调用,且会自动将 self.RTGMesh 作为第一个参数传递给方法。

self.RTGMesh.SetAnimClass(ABP_Lin_Class):这种写法使用了点 . 来调用方法。在这种情况下,你需要显式地将 self.RTGMesh 作为第一个参数传递给 SetAnimClass 方法,因为点 . 调用方法时不会自动传递对象本身。如果 SetAnimClass 方法期望的第一个参数是一个 UObject 类型(userdata),但你传递了一个 UClass 类型(ABP_Lin_Class),就会出现类型不匹配的错误。

根据你提供的错误信息来看,self.RTGMesh 应该是一个 UObject 实例,但在第二种写法中,你传递了一个 UClass 类型(ABP_Lin_Class)。这导致了类型不匹配的错误。

所以,正确的做法是使用第一种写法,也就是 self.RTGMesh:SetAnimClass(ABP_Lin_Class),这会正确地将 self.RTGMesh 作为第一个参数传递给 SetAnimClass 方法。

问了下chatGPT,才发现:和.符号问题,:会将自己当作第一个参数,不过c++方法没有第一个UObject函数,就很神奇。

from sluaunreal.

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.