x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

calling c++ functions of another class in blueprint

Hello there! The topic isnt really clear I know, its just I do not know how to ask it, Now let me say this first, I consider myself to be very good in c++ and I have made very big programs in c++ and other languages, I have been making 2d games using allegro library, and it is different than unreal engine, and I guess that is because in allegro I can use my native C syntax, but I could not do it in Unreal engine now, I have a class called countdown, this class will count from 3 to 0 and then wil be destroyed, my health class is just simple class that contains some functions/methods to reduce health && return health value, what I was thinking is I want to start reducing health after the countdown hits 0; and I want to know how do I implement that both in blue print and in C++ files,

 //countdown
 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "QuickStart.h"
 #include "Countdown.h"
 
 
 // Sets default values
 ACountdown::ACountdown()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("CountdownNumber"));
     CountdownText->SetHorizontalAlignment(EHTA_Center);
     CountdownText->SetWorldSize(150.0f);
     RootComponent = CountdownText;
     CountdownTime = 3;
     
     
 }
 
 // Called when the game starts or when spawned
 void ACountdown::BeginPlay()
 {
     Super::BeginPlay();
     
     UpdateTimerDisplay();
     GetWorldTimerManager().SetTimer(CountdownTimerHandle, this, &ACountdown::AdvancedTimer, 1.0f, true);
 
 }
 
 // Called every frame
 void ACountdown::Tick( float DeltaTime )
 {
     Super::Tick( DeltaTime );
 
 }
 
 void ACountdown::UpdateTimerDisplay()
 {
     
     if (CountdownTime >= 1)
     {
         CountdownText->SetText(FString::FromInt(FMath::Max(CountdownTime, 0)));
         UE_LOG(LogTemp, Warning, TEXT("Countdown for go %d"), CountdownTime);
     }
 }
 
 void ACountdown::AdvancedTimer()
 
 {
     --CountdownTime;
     
     UpdateTimerDisplay();
     if (CountdownTime == 0)
     {
         
         CountdownHasFinished();
         
     }
      if (CountdownTime < -1)// destroy "GO" text after one second of showing
     {
         CountdownText->DestroyComponent(true);
         //UE_LOG(LogTemp, Warning, TEXT("Destoying that thing"));
         //UE_LOG(LogTemp, Warning, TEXT("health %d"), health);
         GetWorldTimerManager().ClearTimer(CountdownTimerHandle);
     }
 
 }
 
 void ACountdown::CountdownHasFinished_Implementation()
 {
     CountdownText->SetText(TEXT("GO!"));
     
     
     
 }



 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "QuickStart.h"
 #include "HealthActor.h"
 
 
 // Sets default values
 AHealthActor::AHealthActor()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     health = 100.0f;
 }
 
 
 void AHealthActor::reduceHealth()
 {
     health -= 20;
     UE_LOG(LogTemp, Warning, TEXT("health %f"), health);
     GetHealth();
     
 }
 
 float AHealthActor::GetHealth()
 {
     UE_LOG(LogTemp, Warning, TEXT("health %f"), health);
     return health;
 }
 // Called when the game starts or when spawned
 void AHealthActor::BeginPlay()
 {
     Super::BeginPlay();
     
 }
 
 // Called every frame
 void AHealthActor::Tick( float DeltaTime )
 {
     Super::Tick( DeltaTime );
 
 }
 

Now in my blueprint I do this for countdown

alt text

What I want to know is

now in this blue print, how can I call the reduce health to be reduced when countdown is finished, and if I want to do it in code, what is the way to do this, because i tried to create health object in countdown this way AHealthActor* myhealth; myhealth->health = 100.0f; but it crashed the system. also if you have links that will get me going, please put them here too, because I have read all unreal programming guide, but still though I am confused, it would help to have more sources to read from :) thanks for your help, :)

Product Version: UE 4.8
Tags:
countdown.png (175.2 kB)
more ▼

asked Jun 23 '15 at 04:15 AM in C++ Programming

avatar image

CaVeMaN150
5 1 2 4

avatar image CaVeMaN150 Jun 23 '15 at 05:27 AM

Alright, I have being missing around since I asked this question, and I figured the blueprint part, but I still need the c++ part, because if I create an object of health it breaks. as for how I did it in blue print is I did this 1- I created a variable of type object reference, then I made it editable in the (exposed it) /made it public, to be edited in the details panel, then in the details panel I choose the class blue print "health" and I was able to get the values and reduce it. here is a picture of my blue print alt text

blueprint.png (266.8 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Haha I remember allegro XD
So you want counter to be a completely different class? You can make a new object from the second class in the other class's header like (include your timer class header as well)

 UPROPERTY(EditDefaultsOnly, Category = Timer, meta = (AllowPrivateAccess = "true"))
         TSubclassOf<class AMyTimer >TimerClass;



thin in the CPP file if you wanted to attach the timer to a blueprint you made you would then do something like :

 static ConstructorHelpers::FObjectFinder<UBlueprint> PlayerTimerBlueprint(TEXT("Blueprint'/Game/blueprint/Mytimer.Mytimer'"));
 
 TimerClass = NULL;
 
 if (PlayerTimerBlueprint.Succeeded())
 {
     TimerClass = (UClass*)PlayerTimerBlueprint.Object->GeneratedClass;
 
 }


Then you could get whatever you needed from the timer class.

  • don't know blueprint scripting

more ▼

answered Jun 23 '15 at 05:33 AM

avatar image

spazchicken
447 35 20 53

avatar image CaVeMaN150 Jun 24 '15 at 07:40 AM

Thanks! took me time to realize that this was the solution lol, had to go through some unreal programming tutorials then found out that this was the solution :p ty

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question