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

Standalone Game Bind GameInstance #396

Closed
43602410 opened this issue Apr 19, 2022 · 2 comments
Closed

Standalone Game Bind GameInstance #396

43602410 opened this issue Apr 19, 2022 · 2 comments

Comments

@43602410
Copy link

在编辑器下运行独立模式时 绑定GameInstance 会出现绑定不上的问题
FLuaContext::PostLoadMapWithWorld(UWorld* World)
用 #if !WITH_EDITOR 判断 为什么不是 if (!GIsEditor) 运行时判断?
同时 FLuaContext::OnPostEngineInit()
#if AUTO_UNLUA_STARTUP && !WITH_EDITOR、
应改为
#if AUTO_UNLUA_STARTUP
if (!GIsEditor)
{
SetEnable(true);
}
#endif

另外 GameInstance 的绑定应该早于GameMode 为什么不在PreLoadMap 绑定GameInstance?

@zbjxb
Copy link

zbjxb commented Apr 21, 2022

在编辑器下运行独立模式时 绑定GameInstance 会出现绑定不上的问题 FLuaContext::PostLoadMapWithWorld(UWorld* World) 用 #if !WITH_EDITOR 判断 为什么不是 if (!GIsEditor) 运行时判断? 同时 FLuaContext::OnPostEngineInit() #if AUTO_UNLUA_STARTUP && !WITH_EDITOR、 应改为 #if AUTO_UNLUA_STARTUP if (!GIsEditor) { SetEnable(true); } #endif

另外 GameInstance 的绑定应该早于GameMode 为什么不在PreLoadMap 绑定GameInstance?

尝试了一下,把UnLuaModule.cpp里的WITH_EDITOR改成GIsEditor后就修复了Standalone模式绑定GameInstance失败的问题,同时经过测试,编辑器PIE模式以及工程打包之后运行都没有问题。我还给UnLua里加了一个UnLua::AddPackagePathAndCPathForUEPlugin(UnLua::GetState(), "UnLua");函数,方便用户自己的插件里的Content/Script目录下的lua脚本也能正常require使用。

class FUnLuaModule : public IModuleInterface
{
public:
    virtual void StartupModule() override
    {
    	FLuaContext::Create();
        GLuaCxt->RegisterDelegates();

		// Register Delegates
		Handle_UnLuaRegisterLuaPath = FUnLuaDelegates::OnLuaContextInitialized.AddLambda(
        []()
        {
	        UnLua::AddPackagePathAndCPathForUEPlugin(UnLua::GetState(), "UnLua");
            require_socket_core(UnLua::GetState());
        });

#if AUTO_UNLUA_STARTUP
        if(!GIsEditor)
        {
		GLuaCxt->SetEnable(true);
        }
#endif
	}

    virtual void ShutdownModule() override
    {
		FUnLuaDelegates::OnLuaContextInitialized.Remove(Handle_UnLuaRegisterLuaPath);
    }
};

另外,我使用的UnLua的版本是master分支的be0265a加上develop分支的cf455c8号commit

@xuyanghuang-tencent xuyanghuang-tencent added the pending release This will be released on next version label May 5, 2022
@xuyanghuang-tencent
Copy link
Collaborator

v2.2.0

@xuyanghuang-tencent xuyanghuang-tencent removed the pending release This will be released on next version label Nov 7, 2023
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

No branches or pull requests

3 participants