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"

Property not being set in code or blueprints

Good Day,

I have just migrated my project to 4.8 (its not a critical project) but I have run into an unusual bug.

I have set my property in my header file as such:

 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Bomb)
 float ExplosionDamage;

and in my constructor in my source file I set is like so:

 // 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;

 BombMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BombMesh"));
 RootComponent = BombMesh;
 
 sphereCollision = CreateDefaultSubobject<USphereComponent>(TEXT("SphereCollision"));
 sphereCollision->SetSimulatePhysics(true);
 sphereCollision->SetSphereRadius(explosionRadius);
 sphereCollision->AttachTo(RootComponent);

 BombExplosion = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("BombExplosion"));
 BombExplosion->bAutoActivate = false;
 
 
 //projectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovement"));

 fuseTime = 3.0f;
 ExplosionDamage = 30;
 UE_LOG(LogTemp, Warning, TEXT("Damage = %d"), ExplosionDamage);

In order to give it a default value. However when I set up a log point directly after that it returns 0, telling me that it has not been set at all. It gives the same result in BeginPlay().

I also noticed that even if I use a hard coded 30 damage into the TakeDamage function like so:

 testActor->TakeDamage(30, DamageEvent, GetInstigatorController(), this);

The ReceiveAnyDamage event does not fire. Was this changed somehow for 4.8?

Product Version: UE 4.8
Tags:
more ▼

asked Jun 29 '15 at 01:32 PM in C++ Programming

avatar image

iRperson
3 3 5

avatar image Shadowriver Jun 29 '15 at 02:35 PM

Where do you call UE_LOG and TakeDamage?

avatar image iRperson Jun 29 '15 at 02:45 PM

I call UE_LOG immediately after initialising the variable in the constructor, it still returns 0. Take damage is when the bomb explodes and should send a "damageRecieved" event, but it doesn't (because the damage passed is being read as 0, even when hard coded)

avatar image Shadowriver Jun 29 '15 at 02:58 PM

Well checking varables in constructor might give odd results, so you should check it in BeginPlay. When you create blueprint from this class do damage is properly set in defaults? Maybe paste whole constructor

avatar image iRperson Jun 30 '15 at 07:40 AM

It gives the same result when I call it inside BeginPlay(). Updated the constructor code. I do not alter the value anywhere in the code, its only given a default value and then I can adjust the damage in the blueprint.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Checking variables in the constructor is perfectly fine - C++ would be pretty unusable if that would not be the case.

However "ExplosionDamage" is of type "float" and your UE_LOG prints out that float as an "int" because you are using "%d". So this will give you wrong output at least.

Why not just set a breakpoint and check what the Debugger tells you about that variable?

Also, just step into the TakeDamage() code and see what is happening. As you can see the damage may get modified by InternalTakePointDamage() or InternalTakeRadialDamage(). If the "Actual Damage" ends up with 0, the "ReceiveAnyDamage" event will never be called.

Marc

more ▼

answered Jun 30 '15 at 03:01 PM

avatar image

mkamradt
294 15 136 34

avatar image iRperson Jul 01 '15 at 05:27 AM

Thank-you for pointing out the error in my UE_LOG, I didn't read the docs correctly on that, after reading them again and changing it, I am getting the correct readout now, I will go through the TakeDamage code and see what is happening there.

(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