当前位置:   article > 正文

UE5 C++ 静态加载资源和类

UE5 C++ 静态加载资源和类

一.上篇文章创建组件并绑定之后

在Actor中加载初始化了组件,现在在组件中赋值。使用static ConstructorHelpers::FObjectFinder<T>TempName(TEXT("Copy Reference"));再用TempName.Object

  1. //静态加载资源
  2. static ConstructorHelpers::FObjectFinder<UStaticMesh>TempStaticMesh(TEXT("/Script/Engine.StaticMesh'/Game/StarterContent/Shapes/Shape_Torus.Shape_Torus'"));
  3. MyMesh->SetStaticMesh(TempStaticMesh.Object); //设置模型
  4. static ConstructorHelpers::FObjectFinder<UParticleSystem>TempParticleSystem(TEXT("/Script/Engine.ParticleSystem'/Game/StarterContent/Particles/P_Steam_Lit.P_Steam_Lit'")); //Copy Reference
  5. MyParticle->SetTemplate(TempParticleSystem.Object);
  6. static ConstructorHelpers::FObjectFinder<USoundWave>TempSound(TEXT("/Script/Engine.SoundWave'/Game/StarterContent/Audio/Explosion02.Explosion02'"));
  7. MyAudio->SetSound(TempSound.Object);

里面的资源都来自StarterContent

 

效果如下:

二.静态加载类

1.在Actor中再声明一个AActor类 

2.在静态加载类时使用

static ConstructorHelpers::FClassFinder<AActor>TempName(TEXT("Copy Reference_C"))

_C需要在 Copy Reference中自带的 ' 内(最后一个字母后面)

再赋值TempName.Class

  1. //静态加载类
  2. static ConstructorHelpers::FClassFinder<AActor>TempMyActor(TEXT("/Script/Engine.Blueprint'/Game/StarterContent/Blueprints/Blueprint_CeilingLight.Blueprint_CeilingLight_C'")); //资源类一定要加_C
  3. MyActor = TempMyActor.Class;

测试一下

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/133127
推荐阅读
相关标签
  

闽ICP备14008679号