Pragma url: https://searcheng.in/e/z/wpiytv
Contributor
Become a Contributor
  • 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

    By: ChatGPT AI
    0 Μοιράστηκε
  • once

    #include "CoreMinimal.h"
    #include "GameFramework/Character.h"
    #include "PlayerCharacter.generated.h"

    UCLASS()
    class CPP_PROJECT_API APlayerCharacter : public ACharacter
    {
    GENERATED_BODY()

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class USpringArmComponent* CameraBoom;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class UCameraComponent* FollowCamera;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class UArrowComponent* Arrow;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
    class UStaticMeshComponent* MeshComp;

    UPROPERTY(EditDefaultsOnly)
    float Speed;

    UPROPERTY(EditDefaultsOnly)
    float RotationSpeed;

    public: // Public functions for use in blueprints and c++ code.

    APlayerCharacter(); // Constructor for the class.

    /** Returns CameraBoom subobject **/ // Used to get the camera boom subobject from the player character class in blueprints.
    FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }

    /** Returns FollowCamera subobject **/ // Used to get the follow camera subobject from the player character class in blueprints.
    FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }

    /** Returns Arrow subobject **/ // Used to get the arrow subobject from the player character class in blueprints.
    FORCEINLINE class UArrowComponent* GetArrow() const { return Arrow; }

    /** Returns MeshComp subobject **/ // Used to get the mesh comp subobject from the player character class in blueprints.
    FORCEINLINE class UStaticMeshComponent* GetMeshComp() const { return MeshComp; }

    void MoveForward(float Value); // Function used to move forward and backward with a float value between -1 and 1 as input parameter.

    void MoveRight(float Value); // Function used to move right and left with a float value between -1 and 1 as input parameter.

    void RotateYaw(float Value); // Function used to rotate around yaw axis with a float value between -1 and 1 as input parameter.

    protected: // Protected functions for use only within this base class or any derived classes of it's parent classes..

    virtual void BeginPlay() override; // Override function for when play begins for this character..

    virtual void Tick(float DeltaTime) override; // Override function for ticking every frame..
    };

    By: ChatGPT AI
    0 Μοιράστηκε
Contributor
Become a Contributor

Please Wait....

Password Copied!

Please Wait....