post the code for BCRouge.cpp. I’ll check if there are any other problems.
there could be a problem either when trying to access PhysMat if it’s not set or when you try to set the physics material override if it or the mesh you are setting it on are nulls
Ok, but despite the fact that i have changed the code, the error is still the same.
// Fill out your copyright notice in the Description page of Project Settings.
include “MyGameInstance.h” include “Kismet/GameplayStatics.h” include "Runtime/Engine/Classes/Components/StaticMeshComponent.h " include “PhysicalMaterials/PhysicalMaterial.h”
// Sets default values
ABCRouge::ABCRouge()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
apparently, doing this enable my programme to work : 1. delete intermediate and binaries folders.
2. regenerate the project.
3. rebuild
4. and try again.
does it still happen?
It’s ok, i had to delete intermediate and binaries folders. If i had well anderstand, the PhysMat created is a PhysicalMaterial that i have to set in the cdo ? If yes, how do i do this ? As you see i tried PhysMat->Friction = 0; but it made ue crash.
Thanks for following my project and answering my question since the beginning !
// 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
I put this but apparently, physMat = nuulptr bcs the physmat don’t appear in the editor and i tried this : GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, (“Friction”)); But nothing appeared.
Oh nice, so i set it but “Friction” Don’t appear as if PhysMat = nullptr and even if i set this for the ball in game, the one who arrived during game won’t have it set.
Hi, sorry for all of this, i have just understand that a project can’t be only in c++ or BP. SO by using c++ to make the actor spawn and BP for the actor, i fix the issue. Last but not least i’ve again a probleme, i want to make a bouncy ball but the ball is losing speed even thought i set friction to 0 and bounciness to 1. Thank you so much