Take damage, destruct mesh if damage is enough: // Take damage UFUNCTION(BlueprintCallable, Category="Components|Destructible") virtual void UDestructibleComponent::ApplyDamage(float DamageAmount, const FVector& HitLocation, const FVector& ImpulseDir, float ImpulseStrength) override; // Take radius damage UFUNCTION(BlueprintCallable, Category="Components|Destructible") virtual void UDestructibleComponent::ApplyRadiusDamage(float BaseDamage, const FVector& HurtOrigin, float DamageRadius, float ImpulseStrength, bool bFullDamage) override;

Continue reading

Problem: There’s a bug that DestructibleComponent isn’t affectd by SetActorEnableCollision or SetCollisionEnabled. Solution: Add a custom Component inherit from DestructibleComponent, then override two functions: OnActorEnableCollisionChanged, SetCollisionEnabled // Copyright 2015 inbetweengames #include "ProjectDisco.h" #include "DADestructibleComponent.h" void UDADestructibleComponent::OnActorEnableCollisionChanged() { // Update physical properties of the chunks in the mesh if the body instance is valid FBodyInstance* BodyInst = GetBodyInstance(); if (BodyInst) { BodyInst->UpdatePhysicsFilterData(); } // Update physical properties for individual bone instances as well if (SkeletalMesh) { int32 NumBones = SkeletalMesh->RefSkeleton.

Continue reading

Futuristic modular top-down rooftop https://cubebrush.co/matima-studio/products/cdfga-vJET/futuristic-modular-top-down-rooftop Overgrown Ruins https://cubebrush.co/matima-studio/products/txm3yg-vfju/overgrown-ruins https://www.mawiunited.com/ https://www.matima-studio.com/assets

Continue reading

UE4 Plugin Link Error: Error LNK2019 unresolved external symbol "private: static class UClass * __cdecl UMyComponent::GetPrivateStaticClass(void)" (?GetPrivateStaticClass@UMyComponent@@CAPEAVUClass@@XZ) referenced in function "class UMyComponent * __cdecl NewObject<class UMyComponent>(class UObject *)" (??$NewObject@VUMyComponent@@@@YAPEAVUMyComponent@@PEAVUObject@@@Z) ClimbWall Reason: Maybe you removed UE4’s macro in your header. Solution: Add UE4 stylized macro in header, e.g.: UCLASS() class TESTPLUGIN_API UMyComponent : public UActorComponent { GENERATED_BODY() }

Continue reading

对于结构简单的模型,使用UE4自动生成的Simple Collision没什么问题;如果模型结构复杂,使用Simple Collision不够精准,使用Complex Collision对于实时计算(比如开放世界大场景的游戏项目)的项目来说太耗。 UE4中自定义碰撞盒 Static Mesh默认打开后: 勾选 Simple Collision 然后选中 Collision,按Delete键删掉 然后点击菜单 Collision -》 Add Box Simplified Collision 然后就可以按W、E、R键修改 Box的坐标、转向、缩放等 由于缩放比例是按倍数调整的,所以一个box很难完整包裹物体,这个时候可以使用多个Box组合,例如: 官方文档: Setting Up Collisions With Static Meshes https://docs.unrealengine.com/en-us/Engine/Content/Types/StaticMeshes/HowTo/SettingCollision 在3DMax、Maya中创建自定义碰撞盒 UE4编辑器中虽然提供了添加自定义碰撞盒的功能,但是编辑起来不够灵活,对于特殊行的物体,建议在建模软件中创建自定义碰撞盒。 1,比如U型物体,UE4自动生成的碰撞盒子是这样的: 简单碰撞 复杂碰撞 2,我们在建模软件中(这里以Maya为例),为U型物体添加三块遮挡方块 将U型物体和3个方块合成一个Group,并且碰撞盒子的命名一定要遵循规则:UCX_主物体名XXX。例如:主物体名称为pCylinder,则碰撞盒子的名称必须为:UCX_pCylinderXXX,否则导入UE4后这3个方块会被当作真实物体而不是碰撞体。 然后导出FBX文件,导入UE4时,去掉勾选:Auto Generate Collision;如果碰撞盒子没有和模型合成一个Group,还需要勾选:Combine Meshes。这里我们已经在Maya进行了Group操作,所以可以不用勾选 Combine Meshes。 导入UE4后,编辑器中打开该物体,然后勾选:Collision -》 Simple Collision 就可以看到3块自定义碰撞盒。

Continue reading

[UE4]Root Motion

蓝图设置方式 Root Motion 设置步骤: 先在 AnimSequence 的Asset Detail面板中勾选EnableRootMotion和Force Root Lock。 然后基于该 AnimSequence 新建一个 AnimMontage。 然后再在 AnimationBluerpint 中设置Root Motion Mode为 Root Motion From Montages Only(Class Defaults 面板下,不是Class Settings)。 如果你没有使用UE4的服务器、或者使用了UE4服务器但是没有对动画启用Replication(服务端通过 NetMulticast 播放动画),设置为Root Motion from Enerything没有问题,如果使用了UE4的Replication,且这些动画文件(AnimSequence, Blendspace, AnimMontage, etc.)勾选了EnableRootMotion,那么 Root Motion 也会被同步,影响性能。所以官方文档上的建议是使用默认设置,即:Root Motion Mode设置为Root Motion From Montages Only,只对Montage的Root Motion进行Replication。 Root Motion https://docs.unrealengine.com/en-US/Engine/Animation/RootMotion C++设置方式 UAnimMontage 的两个属性 bEnableRootMotionTranslation、bEnableRootMotionRotation,任意一个设置为 true 即可。 AnimMontage.cpp 引擎代码: bool bRootMotionEnabled = bEnableRootMotionTranslation || bEnableRootMotionRotation; if (bRootMotionEnabled) { for (FSlotAnimationTrack& Slot : SlotAnimTracks) { for (FAnimSegment& Segment : Slot.

Continue reading

enum 1, define UENUM() enum Status { Stopped UMETA(DisplayName = "Stopped"), Moving UMETA(DisplayName = "Moving"), Attacking UMETA(DisplayName = "Attacking"), }; 2, using UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Status) TEnumAsByte<Status> Status; struct 1, define USTRUCT(BlueprintType) struct TESTPROJ_API FMyStruct { GENERATED_USTRUCT_BODY() UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Test") int32 Test; FMyStruct() { } }; 2, using UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) FMyStruct Test;

Continue reading

[UE4]Assertions

Reporting errors and halting execution. check(): like assert() in C, can be disabled by DO_CHECK 0 verify(): like check(), but the expression is still executed on DO_CHECK 0 (e.g. for variable assignments) disadvantage: halts program execution (application ends, Editor users can loose unsaved work). when to use: catch fatal errors Reporting errors and halting execution exclusively in debug builds. checkSlow(), checkfSlow(), verifySlow() (see (1)) difference to (1): they are only active in debug builds (when DO_GUARD_SLOW 1)

Continue reading

Creating Interactive Grass in Unreal Engine 4 https://www.raywenderlich.com/6314-creating-interactive-grass-in-unreal-engine-4 Creating Snow Trails in Unreal Engine 4 https://www.raywenderlich.com/5760-creating-snow-trails-in-unreal-engine-4 Dynamic Mesh Painting in Unreal Engine 4 https://www.raywenderlich.com/6817-dynamic-mesh-painting-in-unreal-engine-4 Custom Depth in Unreal Engine 4 https://www.tomlooman.com/the-many-uses-of-custom-depth-in-unreal-4/

Continue reading

Error 1 Error Log: A problem occurred configuring root project 'app'. > Could not resolve all files for configuration ':classpath'. > Could not download kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.1.3-2) > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.1.3-2/kotlin-reflect-1.1.3-2.jar'. > Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.1.3-2/kotlin-reflect-1.1.3-2.jar'. > Software caused connection abort: recv failed > Could not download protobuf-java.jar (com.google.protobuf:protobuf-java:3.0.0) > Could not get resource 'https://jcenter.bintray.com/com/google/protobuf/protobuf-java/3.0.0/protobuf-java-3.0.0.jar'. > Could not GET 'https://jcenter.bintray.com/com/google/protobuf/protobuf-java/3.0.0/protobuf-java-3.0.0.jar'. > Software caused connection abort: recv failed Solution:

Continue reading

Keywords:运行时期间修改后处理设置, change post process settings when game is running. 运行时修改Post Process 步骤 1,使用 Camera Component 拉出 Set members in PostProcessSettings 节点。 Get reference to Camera Component and drag out “Set members in PostProcessSettings” node. 2,选中 Set members in PostProcessSettings 节点,然后再在 Detail 面板中勾选需要修改的属性。比如我想修改曝光亮度。 select “Set members in PostProcessSettings” node, then checked properties which want to modify in Detail Panel. e.g. Brightness of Exposure. 3,将 Camera 组件的 属性” Post Process Blend Weight” 设置为1,表示完全启用摄像机的 Post Process Settings。0表示完全禁用,0到1的数值表示混合过渡“全完启用”到“完全禁用”之间的渐变效果。

Continue reading

EndPlay、BeginDestroy、Destroy 的调用时机 如果要获取 Actor 销毁时的准确时间点,建议重写 Destroy() 函数,而不是EndPlay()、BeginDestroy()。 官方文档上说 EndPlay 会在执行Destroy的时候触发,但实际上并不会(至少4.20版本中测试过不会),而是当 Actor 所在场景销毁时(比如退出编辑器)才会调用。 BeginDestroy()、IsReadyForFinishDestroy()、FinishDestroy() 是在执行垃圾回收时才会触发的函数,而不是对象被 Destroy 后立即执行的函数。 官方文档 https://docs.unrealengine.com/en-us/Programming/UnrealArchitecture/Actors/ActorLifecycle

Continue reading

UProjectileMovementComponent相关 官方第一人称射击模版项目中,是在构造函数中就设置好了速度: ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComp")); ProjectileMovement->UpdatedComponent = CollisionComp; ProjectileMovement->InitialSpeed = 3000.f; ProjectileMovement->MaxSpeed = 3000.f; ProjectileMovement->bRotationFollowsVelocity = true; ProjectileMovement->bShouldBounce = true; 两个问题: 如何停止移动; 如何在运行时期间修改速度; 问题1解决方法: 默认情况下,Actor spawn之后,就会受到 ProjectileMovement 影响立即移动,如何在 Spawn 之后马上停止移动: ProjectileMovement->Deactivate(); 问题2解决方法: 如何在 Spawn 之后修改 Speed,两种方式: UProjectileMovementComponent->SetVelocityInLocalSpace(FVector NewVelocity); 或者 UProjectileMovementComponent->Velocity = NewVelocity; 前者速度方向是相对于 UProjectileMovementComponent本地坐标系 的相对Rotation,后者速度方向是相对于世界坐标系的绝对Rotation。 注意:当使用 UProjectileMovementComponent 后,UPrimitiveComponent::SetSimulatePhysics() 启用物理会与 ProjectileMovement 冲突。如果要使用物理,那么只能去掉 UProjectileMovementComponent ,使用 Add Impulse 来代替。 参考: Simulate Physics and Projectile Movement Component

Continue reading

UE4 的 TSharedPtr、TWeakObjectPtr 模仿自 C++11 的 shared_ptr 、 weak_ptr 。 TSharedPtr TSharedPtr 相当于对象的引用计数器。每当对 TSharedPtr 赋值一次,该 TSharedPtr 引用对象计数加一,当引用计数为0时,则该对象被自动销毁。TSharedPtr 可以防止 raw pointer 对象被垃圾回收,。 用法: TSharedPtr<TestClass> ObjPtr = MakeShareable(new TestClass()); 如果两个 TSharedPtr 相互赋值,则会导致对象永不释放,导致内存泄漏。 Uobject 不能使用 TSharedPtr 进行引用计数,非UObject才可以;如果一个非UObject的类想加入GC,那么必须继承FGCObject类。 TWeakObjectPtr TWeakObjectPtr 保持的对象不能防止被垃圾回收。若引用的对象在其他地方被销毁,则 TWeakObjectPtr 内部的指针自动将被置为NULL,TWeakObjectPtr::IsValid()会返回false。TSharedPtr 则没有这个作用。 用法: TWeakObjectPtr<MyUObject> ObjPtr = NewObject<MyUObject>(); 参考资料: UE4 TSharedPtr和UObject的垃圾回收 http://www.v5xy.com/?p=808 There’s a Huge Difference, One Will Always Crash https://answers.unrealengine.com/questions/48818/whats-the-difference-between-using-tweakobjectptr.html what is a “weak object pointer”?

Continue reading

Author's picture

Neil Wang

久长唯有品格

To Be Marvelous

Yichang·Hubei