Code Monkey home page Code Monkey logo

Comments (4)

zjhongxian avatar zjhongxian commented on June 12, 2024

image
是这里报错的?可有堆栈和相关变量信息?

from sluaunreal.

yfcyt avatar yfcyt commented on June 12, 2024

image 是这里报错的?可有堆栈和相关变量信息?

谢谢大佬的回复!
是大佬截图的地方报的错,堆栈信息涉及一些商业隐私,不太方便截上来,我完整的描述一下我的情景:

我用的版本是:sluaunreal-2.1.2

我想要定义一个UStruct结构体FPlayerData,从C++传递(const TArray&)到Lua中,想在lua中访问从C++传递过来的FPlayerData数组

1.定义FPlayerData
USTRUCT(BlueprintType)
struct FPlayerData
{
GENERATED_BODY()

public:

UPROPERTY()
FString PlayerName;
UPROPERTY()
FString PlayerId;

};

namespace NS_SLUA
{
DefTypeName(FPlayerData);
DefDeduceType(FPlayerData, Struct);
}

2.定义一个PlayerController,提供一个服务端调用客户端执行的RPC函数
UCLASS()
class UNREALPROJ_API AXXXPlayerController : public APlayerController
{

    //调用Lua代码
    template<class ...ARGS>
    void CallLuaFunc(const char* FuncName, ARGS&& ...args);

   //将数据同步到客户端
    UFUNCTION(Client, Reliable, Category = "XXXX")
    void ClientUpdatePlayer(const TArray<FPlayerData>& PlayerDatas);

}

void AXXXPlayerController::ClientUpdatePlayer_Implementation(const TArray& PlayerDatas)
{
CallLuaFunc("UpdatePlayer", PlayerDatas);
}

template<class ...ARGS>
void AXXXPlayerController::CallLuaFunc(const char* FuncName, ARGS && ...args)
{
auto LuaWidget = Cast(HUDWidget);
if (LuaWidget)
{
auto Self = LuaWidget->GetSelfTable();
if (Self.isValid()) Self.callField(FuncName, Self, std::forward(args)...);
}
}

代码调用过程:

在Server端通过ClientUpdatePlayer将const TArray& PlayerDatas传递到ClientClientUpdatePlayer_Implementation

最终将PlayerDatas通过callField方法传递到了Lua的UpdatePlayer方法中

发现在Lua中无法使用PlayerDatas数据,并且报上面的错误日志

请问一下,应该如何正确的传递自定义的USTRUCT并通过const TArray& 传递到lua层?

from sluaunreal.

zjhongxian avatar zjhongxian commented on June 12, 2024

OK,我明天抽空构造一下现场看看

from sluaunreal.

yfcyt avatar yfcyt commented on June 12, 2024

OK,我明天抽空构造一下现场看看

好的,谢谢大佬

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.