CHATGPT AI
pragma
once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Projectile.generated.h"

class UProjectileMovementComponent;
class UStaticMeshComponent;
class UParticleSystemComponent;
class URadialForceComponent;

UCLASS()
class BATTLETANK_API AProjectile : public AActor
{
GENERATED_BODY()

UPROPERTY(VisibleAnywhere, Category = "Components")
UStaticMeshComponent* CollisionMesh = nullptr;

UPROPERTY(VisibleAnywhere, Category = "Components") // This is a subobject of the projectile class, so it's not necessary to destroy it in the destructor. It will be destroyed automatically when the projectile is destroyed. So no need for a smart pointer here. We just use a raw pointer and let UE4 take care of destroying it for us when the projectile is destroyed. This is called ownership chaining and it's common in UE4 and other game engines. It's also why we don't need to call Destroy() on any of these components in the destructor of this class (the engine will do that for us). We just need to make sure we set them to nullptr so that they don't point to invalid memory locations after they are destroyed (which could cause a crash). That's why we set them all to nullptr in the destructor of this class. https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Actors/Components/index.html See section on Ownership Chaining & Component Lifecycle Management for more info about this topic (it's important to understand!). Also see section on Component Destruction Order for more info about how components are destroyed when their owning Actor is destroyed (this can be important if you have components that rely on each other). https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Actors/Components/DestructionOrder/index.html Also note that if you have components that rely on each other, then you should create them in the same order as their dependencies (i.e., create component A first, then component B which depends on A, etc.). This will ensure that components are created & destroyed in the correct order so that they don't try to access invalid memory locations after they are destroyed (which can cause crashes). https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Actors/Components/#componentcreationorder Hope this helps! :) Good luck! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :):) UProjectileMovementComponent* ProjectileMovement = nullptr;

UPROPERTY(VisibleAnywhere, Category = "Components") // This is just an effect component so no need for smart pointer or ownership chaining here either since effects are short lived and will be automatically cleaned up by UE4 when their owning Actor is destroyed anyway (no need for us to manually clean up effects like we do with Components since they are short lived and will be cleaned up by UE4 automatically). https://docs.unrealengine
once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "Projectile.generated.h" class UProjectileMovementComponent; class UStaticMeshComponent; class UParticleSystemComponent; class URadialForceComponent; UCLASS() class BATTLETANK_API AProjectile : public AActor { GENERATED_BODY() UPROPERTY(VisibleAnywhere, Category = "Components") UStaticMeshComponent* CollisionMesh = nullptr; UPROPERTY(VisibleAnywhere, Category = "Components") // This is a subobject of the projectile class, so it's not necessary to destroy it in the destructor. It will be destroyed automatically when the projectile is destroyed. So no need for a smart pointer here. We just use a raw pointer and let UE4 take care of destroying it for us when the projectile is destroyed. This is called ownership chaining and it's common in UE4 and other game engines. It's also why we don't need to call Destroy() on any of these components in the destructor of this class (the engine will do that for us). We just need to make sure we set them to nullptr so that they don't point to invalid memory locations after they are destroyed (which could cause a crash). That's why we set them all to nullptr in the destructor of this class. https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Actors/Components/index.html See section on Ownership Chaining & Component Lifecycle Management for more info about this topic (it's important to understand!). Also see section on Component Destruction Order for more info about how components are destroyed when their owning Actor is destroyed (this can be important if you have components that rely on each other). https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Actors/Components/DestructionOrder/index.html Also note that if you have components that rely on each other, then you should create them in the same order as their dependencies (i.e., create component A first, then component B which depends on A, etc.). This will ensure that components are created & destroyed in the correct order so that they don't try to access invalid memory locations after they are destroyed (which can cause crashes). https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Actors/Components/#componentcreationorder Hope this helps! :) Good luck! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :) Phew.. That was a lot of info... lol ;) Hope it helps! :) -Ryan from Epic Games Support Team :):) UProjectileMovementComponent* ProjectileMovement = nullptr; UPROPERTY(VisibleAnywhere, Category = "Components") // This is just an effect component so no need for smart pointer or ownership chaining here either since effects are short lived and will be automatically cleaned up by UE4 when their owning Actor is destroyed anyway (no need for us to manually clean up effects like we do with Components since they are short lived and will be cleaned up by UE4 automatically). https://docs.unrealengine
0 Comments & Tags 0 Μοιράστηκε 1 Views

Password Copied!

Please Wait....