Crash for no reason | C++

Try this code:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

include "CoreMinimal.h"
include "Components/ActorComponent.h"
include "MagicComponent.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT2_API UMagicComponent : public UActorComponent
{
	GENERATED_BODY()

	public:
		UMagicComponent();
		
		virtual void BeginPlay() override;
		virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

		void UseSpell();
		void UseSpellWithCast();

		FString GetSpellName();
		void Casting();
		
		UFUNCTION(BlueprintCallable)
		void ChangeSpell(TSubclassOf<class ASpells_Base> NewSpell);

	public:
		UPROPERTY(EditAnywhere)
		TSubclassOf<class ASpells_Base> MagicImpulseClass;

		UPROPERTY(EditAnywhere)
		TSubclassOf<class ASpells_Base> MagicBlastClass;

		UPROPERTY()
		TObjectPtr<ASpells_Base> CurrentSpell;

		UPROPERTY(EditAnywhere)	
		TObjectPtr<UUserWidget> CastWidget;

		UPROPERTY(EditAnywhere)
		TSubclassOf<class UUserWidget> SpellCastWidget;

		UPROPERTY()
		TScriptInterface<IINF_MainChar> CompOwner;
		
		FTimerHandle MyTimerHandle;
		bool bCanDoMagic=true;

	private:
		UPROPERTY(EditAnywhere)
		TSubclassOf FirstSpellClass;

		UPROPERTY()
		TSubclassOf CurrentSpellClass;

};

To use TScriptInterface<>:
https://isaratech.com/ue4-declaring-and-using-interfaces-in-c/

If it still doesn’t work:

  • Restart the editor
  • Delete your Character Blueprint, restart the Editor and create it again.