Inheritance help

UPDATE: i did more tests on it and when i shoot my logs go 2,3,1 when it should be 1,2,3 all 3 functions are being called on fire but i dont know if the numbers are meant to be in order or not as i put them in order in which they should go in and when i do shoot my gun doesn’t shoot just the log prints

Inside my character .h i allow the user to set any gun to be the primary weapon



	UPROPERTY(EditDefaultsOnly, Category = "Setup")
		TSubclassOf<class AWeaponBase> PrimaryWeaponBlueprint;

	UPROPERTY(EditDefaultsOnly, Category = "Setup")
		class AWeaponBase* PrimaryWeapon;


Inside my character beginplay i spawn my gun


PrimaryWeapon = GetWorld()->SpawnActor<AWeaponBase>(PrimaryWeaponBlueprint);

Then i make the shoot method also in my character class



void ALearnProjectCharacter::OnFire() {
	PrimaryWeapon->WeaponFire();
}


then in my weaponbase class i have an empty shoot method



void AWeaponBase::WeaponFire() {

}


And then i set it in the .h file


virtual void WeaponFire();

then i made a child class of the weapon base and override the function from the weaponbase class


void WeaponFire() override;

then i setup my gun shooting logic inside of it



void AWeapon_Scar::WeaponFire() {
      Super::WeaponFire();
ShootingLogic Here
}


An easy place to start is placing break points at each step and seeing where your logic is failing. Using UE_LOG() helps alot as well

Forgot about them it seems to be the “PrimaryWeapon->WeaponFire()” is not being called and i dont know why you got any ideas?

where are you calling ALearnProjectCharacter::OnFire()?

Yes i call that and then it should do “PrimaryWeapon->WeaponFire();” which is in my weaponbase call which is empty but i have a child class that overrides the weaponfire function and that has all the logic in for my gun. My log in my fire logic is working but when i put it in my line trace it doesn’t work so i think that nothing in my fire logic is being called only the things are the top line of it is

When you say it “Should do” always verify that is indeed happening. Place a breakpoint in that function. When that breakpoint hits step through the function to see where its taking you

I dont always use breakpoints i normally only use logs but i used a break point on this part and this is the first place where the error starts i think its something to do with “Character” but i could be wrong so actually all of the three functions are being called it just stops when it hits that line in the 3rd function which causes it to not continue as it says its a access violation do you have any idea how i could fix this as this problem did not occur until i made it a child class

check if any of the pointers on that line are null

Yes the Character-> is returning null the only reason it isn’t crashing is because i have a pointer protector above it, I think i know what i need to do just testing it. I think its that since i made a weaponbase and child class i actually unset my Character pointer reference but im not sure yet

Update: Wow thanks man i never had to use break points as the code i write isn’t very complicated and rarely has pointers having that pointer protected has saved me a lot of stress from the constant crashes. the Logs have helped
to find where the problem is occurring and then the break points have helped me to locate the first line that has the error and because it was the line with the pointer and it being an access violation i knew straight away it was because of the pointer and then i realised i had unset the reference to it. So thanks for not spoon feeding me the answer and giving me ways to work it out myself it has helped a lot :slight_smile: