Access Violation when reading variable

Hi, I’ve my character class and create three object of type UOrbObject derived from UObject. Then I initialize through function Initialize() since Uobject doesn’t support passing constructor parameter i suppose. Now I have a function call onStateSwitch to switch different orb object state by pressing different bindaction key, for instant when i press “1” it will call RedOrb->OnStateSwitch(), press “2” GreenOrb->OnStateSwitch(), however in the OnStateSwitch() function in UOrbObject class, when it reads the variable of OrbType, it breaks and appear access violation warning. (Warning appeared after Pressing 1/2/3 key in play on editor). How could I solve this problem?

character.h

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Orb)
	class UOrbObject* RedOrb;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Orb)
	class UOrbObject* GreenOrb;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Orb)
	class UOrbObject* BlueOrb;

character.cpp

RedOrb = NewObject<UOrbObject>();
RedOrb->Initialize(1);

GreenOrb = NewObject <UOrbObject>();
GreenOrb->Initialize(2);

BlueOrb = NewObject<UOrbObject>();
BlueOrb->Initialize(3);

check(RedOrb);
check(GreenOrb);
check(BlueOrb);

OnStateSwitch in character.cpp

void ARGBCharacter::OnStateSwitch(int i)
{
	
	switch (i)
	{
	case 1:
		RedOrb->OnStateSwitch();
		break;

	case 2:
		GreenOrb->OnStateSwitch();
		break;

	case 3:
		BlueOrb->OnStateSwitch();
		break;


	default:
		break;
	}
	
}

UOrbObject.h

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BuffSetting)
		uint8 OrbType;

UOrbObject.cpp

    void UOrbObject::OnStateSwitch()
    {
    	switch (OrbType){ //Problem occurred here
    
    	case 1:
    		UE_LOG(OrbTest, Log, TEXT("Im Red"));
    		break;
    
    	case 2:
    		UE_LOG(OrbTest, Log, TEXT("Im Green"));
    		break;
    
    	case 3:
    		UE_LOG(OrbTest, Log, TEXT("Im Blue"));
    		break;
    		
    	}
    }

void UOrbObject::Initialize(uint8 Type)
{
	OrbType = Type;
}

Hello,

Please note that you should place your Orb Objects initialization in a method that actually gets called.
For example, you can do it in BeginPlay():

void ARGBCharacter::BeginPlay()
{
	Super::BeginPlay();
	RedOrb = NewObject<UOrbObject>();
	RedOrb->Initialize(1);

	GreenOrb = NewObject <UOrbObject>();
	GreenOrb->Initialize(2);

	BlueOrb = NewObject<UOrbObject>();
	BlueOrb->Initialize(3);

	check(RedOrb);
	check(GreenOrb);
	check(BlueOrb);
}

Hope this helped!

Cheers!

Well I thought the ARGBCharacter constructor should already been called once i build the project =/ Btw it works now thanks!