.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "BCRouge.generated.h"
class UProjectileMovementComponent;
UCLASS()
class YOURGAME_API ABCRouge : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actors properties
ABCRouge();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(BlueprintReadWrite,EditAnywhere)
TObjectPtr<UProjectileMovementComponent> BCRougeMovement;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TObjectPtr<USkeletalMeshComponent> BCRougeMeshPhys;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TObjectPtr<UStaticMeshComponent> BCRougeMesh;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPhysicalMaterial* PhysMat;
};
cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "BCRouge.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Kismet/GameplayStatics.h"
#include "MyGameInstance.h"
// Sets default values
ABCRouge::ABCRouge()
{
PrimaryActorTick.bCanEverTick = true;
BCRougeMeshPhys = CreateDefaultSubobject <USkeletalMeshComponent>(TEXT("Skeletal Mesh Comp Phys"));
BCRougeMesh = CreateDefaultSubobject <UStaticMeshComponent>(TEXT("Static Mesh Comp"));
UStaticMesh* SphereMesh = ConstructorHelpers::FObjectFinder <UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'")).Object;
BCRougeMesh->SetStaticMesh(SphereMesh);
BCRougeMesh->SetSimulatePhysics(true);
BCRougeMesh->SetEnableGravity(false);
if (PhysMat != nullptr) {
BCRougeMeshPhys->SetPhysMaterialOverride(PhysMat);
BCRougeMesh->SetPhysMaterialOverride(PhysMat);
PhysMat->Friction = 0;
}
BCRougeMovement = CreateDefaultSubobject <UProjectileMovementComponent>(TEXT("ProjectileMovementComp"));
BCRougeMovement->InitialSpeed = 800;
BCRougeMovement->MaxSpeed = 8500;
BCRougeMovement->Bounciness = 1;
BCRougeMovement->Friction = 0;
BCRougeMovement->Velocity = (FVector(0.f, -1.f, 0.f));
//RootComponent = BCRougeMovement;
RootComponent = BCRougeMesh;
}
// Called when the game starts or when spawned<br>
void ABCRouge::BeginPlay()
{
Super::BeginPlay();
//ConstructorHelpers::FObjectFinder<UStaticMeshComponent>MeshRef(TEXT("Game/ThirdPerson/Meshes/CubeMesh.CubeMesh"));
//BCRougeMesh->SetStaticMesh(MeshRef);
//ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset(TEXT("StaticMesh'/Game/CubeMesh.CubeMesh"));
//UStaticMesh* Asset = MeshAsset.Object;
//BCRougeMesh->SetStaticMesh(Asset);
}
// Called every frame<br>
void ABCRouge::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
UMyGameInstance * MyGameInstance = Cast < UMyGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
if (MyGameInstance)
{
//MyGameInstance->PointBalle2++;
}
}
Not sure why you are setting the friction via c++. The material should probably dictate this value inside the physics material
Not getting any errors after adding the nullptr check