UE5Console 控制台命令


  1. 启动模块,注册

    
    void FAdvModModule::StartupModule()
    {
    	RegisterConsole();
    }
    
    void FAdvModModule::RegisterConsole()
    {
    	IConsoleManager::Get().RegisterConsoleVariable(TEXT("adv.bLocked"), true, TEXT("Lock selected actor!"), ECVF_Scalability | ECVF_RenderThreadSafe);
    }
    
  2. 获取命令状态

    static const auto CVarLocked = IConsoleManager::Get().FindConsoleVariable(TEXT("adv.bLocked"));
    bool bLocked = CVarLocked->GetBool();
    
    if (bLocked)
    {
    	DebugHeader::Print(TEXT("Locked"), FColor::Red);
    }
    else
    {
    	DebugHeader::Print(TEXT("Unlocked"), FColor::Green);
    }
    
  3. 设置状态

    static const auto CVarLocked = IConsoleManager::Get().FindConsoleVariable(TEXT("adv.bLocked"));
    // bool bLocked = CVarLocked->GetBool();
    CVarLocked->Set(true);
    

你可能感兴趣的:(UE5,C++,ue5,控制台命令,Console)