BattleTank (Old v.) Wheel issues

Course: UE4 C++ course. Old version battletank.
Course episode: 223 & 224
Unreal version: 4.26
Issue: After compiling code of episodes 223 and 224 my wheels stopped functioning. I checked the tank blueprint and both side wheels were tacked in one location. So 2 in one spot on the left track and 2 in the same spot on the right track. I tried moving one, but all four move. They’ve also lost their transform locations. If I try and delete them, Unreal crashes.3 image 2.PNG

LINK TO CRASH LOG: https://failiem.lv/u/2hgw6z8uy

It would probably be beneficial if you posted your latest code for your TankTrack.cpp/TankTrack.h file, and your latest repo (if you have been using SouceTree/source control to manage your project)

From what I can tell (not like I am a reliable source) but the log you provided doesn’t tell much.

Last commit: https://github.com/SolidShock/UE4_BattleTank/commit/59468b3fc2fda7099e8889c047d4cf8bb5b7a20b

TankTrack.h

#pragma once

#include "CoreMinimal.h"
#include "Components/StaticMeshComponent.h"
#include "TankTrack.generated.h"

/**
 * TankTrack is used to set maximum driving force and to apply forces to the tank.
 */
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class BATTLETANK_API UTankTrack : public UStaticMeshComponent
{
	GENERATED_BODY()
	
public:
	UFUNCTION(BlueprintCallable, Category = Input)
	void SetThrottle(float Throttle);

	// Max force per track in Newtons.
	UPROPERTY(EditDefaultsOnly)
	float TrackMaxDrivingForce = 60000000.0f;

private:
	UTankTrack();

	TArray<class ASprungWheel*> GetWheels() const;

	void DriveTrack(float CurrentThrottle);
};

TankTrack.cpp

#include "TankTrack.h"
#include "SprungWheel.h"
#include "SpawnPoint.h"

UTankTrack::UTankTrack()
{
	PrimaryComponentTick.bCanEverTick = false;
}

void UTankTrack::SetThrottle(float Throttle)
{
	float CurrentThrottle = FMath::Clamp<float>(Throttle, -1, 1);
	DriveTrack(CurrentThrottle);
}

void UTankTrack::DriveTrack(float CurrentThrottle)
{
	auto ForceApplied = CurrentThrottle * TrackMaxDrivingForce;
	auto Wheels = GetWheels();
	auto ForcePerWheel = ForceApplied / Wheels.Num();
	for (ASprungWheel* Wheel : Wheels)
	{
		Wheel->AddDrivingForce(ForcePerWheel);
	}
}

TArray<ASprungWheel*> UTankTrack::GetWheels() const
{
	TArray<ASprungWheel*> ResultArray;
	TArray<USceneComponent*> Children;
	GetChildrenComponents(true, Children);
	for (USceneComponent* Child : Children) 
	{
		auto SpawnPointChild = Cast<USpawnPoint>(Child);
		if (!SpawnPointChild) continue;

		AActor* SpawnedChild = SpawnPointChild->GetSpawnedActor();
		auto SprungWheel = Cast<ASprungWheel>(SpawnedChild);
		if (!SprungWheel) continue;

		ResultArray.Add(SprungWheel);
	}
	return ResultArray;
}

Do you have a branch with your changes?


That’s the link to my projects commits.
The episodes changes are in commits BT46 and BT47.

I’m asking for where your project is now which doesn’t seem to be where your repo is at as it doesn’t have the code in your previous reply.

Oh sorry. I hadn’t pushed the last changes to the repo.
Should be up there now.
BT48 Test

Yeah I have no idea why that happens. Your best bet is to just recreate the blueprint.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms