What to do to access variables/functions in other C++ class

Hello,

I have two classes: HelicopterTrigger and HelicopterSpawner. Both inherit from AActor. I don’t know how to set a bool variable IsShouldSpawn from HelicopterTrigger to HelicopterSpawner to spawn an object.

In HelicopterSpawner, the bool variable IsShouldSpawn is FALSE and object isn’t spawned, but a trigger in HelicopterTrigger will set the bool variable to TRUE and the object is spawned because if IsShouldSpawn is TRUE, the object is spawned.
In other words, how to communicate between these two classes. How to get the bool variable IsShouldSpawn from HelicopterSpawner inside HelicopterTrigger to set it to other value. Should I cast? But what to what?

Hey Tomza-

One simple solution would be to crate an UpdateShouldSpawn(bool SpawnUpdate) function with a boolean parameter inside your Spawner class. This function can then update the IsShouldSpawn variable based on the boolean passed in using IsShouldSpawn = SpawnUpdate;. Then, to call this function from your Trigger class, you would just need to add AHelicopterSpawner::UpdateShouldSpawn(true/false) where you want the update to occur.

Cheers

Hello ,

Thank you for your answer. I have done that what you said. I have the code in the Spawner class:

//.h

public:
UFUNCTION()
void SetbIsOneBH(bool SpawnUpdate);

bool bIsOneBH;

//.cpp

 void ASpawnBlackHawks::SetbIsOneBH(bool SpawnUpdate) { 
    	bIsOneBH = SpawnUpdate;
    }

And when I try to call it in my Trigger class:

void ABlackHawkTrigger::TriggerEnter(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) {
	
	ASpawnBlackHawks:SetbIsOneBH(true); //HERE: identifier SetbIsOneBH is undefined
	
	
}

And after a compilation SetbIsOneBH: identifier not found.

So the Trigger class doesn’t see the function SetbIsOneBH(true) in the Spawner class.

In reality, I tried this solution before, but still this problem. I can add that I have the Spawner class included in the Trigger class in h. and .cpp.