UE4-【C++】【UE4接入CISQLite3】

末蓝、 2023-06-11 06:23 188阅读 0赞

1.下载插件CISQLite3

2.创建UE4工程,添加Plugins目录和CISQLite3,将1下载到的插件放入Plugins/CISQLite3

3.工程添加uplugin

  1. .uproject添加
  2. "Plugins": [
  3. {
  4. "Name": "CISQLite3",
  5. "Enabled": true
  6. }
  7. ]
  8. UE工程目录.Build.cs 添加模块
  9. PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "CISQLite3" });
  10. 插件目录.Build.cs
  11. public class CISQLite3 : ModuleRules
  12. {
  13. public CISQLite3(ReadOnlyTargetRules Target) : base(Target)
  14. {
  15. bEnableUndefinedIdentifierWarnings = false;
  16. PublicIncludePaths.AddRange(
  17. new string[] {
  18. "CISQLite3/Public"
  19. }
  20. );
  21. PrivateIncludePaths.AddRange(
  22. new string[] {
  23. "CISQLite3/Private"
  24. }
  25. );
  26. PublicDependencyModuleNames.AddRange(
  27. new string[] {
  28. "Engine",
  29. "Core",
  30. "CoreUObject"
  31. }
  32. );
  33. PrivateDependencyModuleNames.AddRange(
  34. new string[] {}
  35. );
  36. DynamicallyLoadedModuleNames.AddRange(
  37. new string[] {}
  38. );
  39. }
  40. }

4.删除工程目录的Binaries和插件Binaries

5.选中.uproject,生成VS解决方案

6.编译

报错:

1.Error:There may be an operating system error or the module may not be properly set up

解决办法:将插件添加到.uproject里即可解决

2.C4668警告错误

解决办法:https://blog.csdn.net/yuxikuo_1/article/details/102799307

7.使用

由于自己没有创建数据库,所以可以从其他demo里下载数据库文件.db

  1. CustomCharacter.h 添加
  2. UFUNCTION(BlueprintCallable, Category = "My Actor")
  3. bool GetMyStats();
  4. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My Actor")
  5. FString Name;
  6. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My Actor")
  7. int32 Age;
  8. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My Actor")
  9. FString Gender;
  10. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My Actor")
  11. float Height;
  12. CustomCharacter.cpp 添加
  13. #include "SQLiteDatabase.h"
  14. bool AMyCharacter::GetMyStats()
  15. {
  16. FString dbName = TEXT("TestDatabase");
  17. FString actorName = TEXT("Bruce Willis");
  18. if (!USQLiteDatabase::IsDatabaseRegistered(dbName))
  19. {
  20. USQLiteDatabase::RegisterDatabase(dbName, "Databases/TestDatabase.db", true);
  21. }
  22. bool didPopulate = USQLiteDatabase::GetDataIntoObject(dbName, FString::Printf(TEXT("SELECT Name, Age, Gender, Height FROM Actors WHERE Name = \"%s\""), *actorName), this);
  23. return didPopulate;
  24. }
  25. void AMyCharacter::BeginPlay()
  26. {
  27. Super::BeginPlay();
  28. bool is_ok = GetMyStats();
  29. if (is_ok)
  30. {
  31. UE_LOG(LogTemp, Log, TEXT("Name = %s"),*Name);
  32. UE_LOG(LogTemp, Log, TEXT("Age = %d"), Age);
  33. UE_LOG(LogTemp, Log, TEXT("Gender = %s"), *Gender);
  34. UE_LOG(LogTemp, Log, TEXT("Height = %f"), Height);
  35. }
  36. }

20191029153439546.png

发表评论

表情:
评论列表 (有 0 条评论,188人围观)

还没有评论,来说两句吧...

相关阅读

    相关 UE4 3DUI的弧度

    想要实现的效果是,展现在页面上的3DUI(即Actor)具备弧度。 修改的位置: ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_1