D
D
db12021-06-04 08:00:22
unreal engine
db1, 2021-06-04 08:00:22

Why doesn't the function work in ue4 c++?

There is a SpawnSphere class - it contains the Actor spawn logic; 1 - at BeginPlay, 2 - the function I created, it does not work when called from outside.

SpherePoint.cpp

#include "SpawnSphere.h" - added

int numberOfDestroy = 0;
void ASpherePoint::OnBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
  
  if (OtherActor != nullptr)
  {
    
    numberOfDestroy++;
    Destroy();
  
    if (numberOfDestroy >= 10)
    {
    
      ASpawnSphere* s = Cast<ASpawnSphere>(SpawnSphere);
    
      if (s != nullptr)
      {
        s->FirstSpawn();
        
        numberOfDestroy = 0;
      }
    }
  }
  
}


SpherePoint.h

public:

UPROPERTY(EditAnywhere, BlueprintReadWrite)
    AActor* SpawnSphere;


SpawnSphere.cpp

void ASpawnSphere::FirstSpawn()
{
...
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question