C++ crash on ChildActorComponent cast outside the owner class

Hello,

EDIT: this wasn’t a problem at all, my bad. My first comment describes a problem I could not solve (the one mentioned in the title atm).

I try to call a C++ function from blueprint. The blueprint node is executed but the C++ function is not called.

(Both the Modify node and the Print String are called).

The C++ function declaration:

UFUNCTION(BlueprintCallable, Category = Modify)
void Modify(float DeltaValue);

Any idea what can be wrong / how to find the problem?

Thanks,

Try deleting the blueprint node and reinserting it. Sometimes if you change a function signature in code, it won’t match the function signature in the backend blueprint script. It’ll look like its executing the function, but it isn’t finding the function anymore since the signature changed and it’s just failing silently.

After restarting the engine, it crashes on a cast :open_mouth:

Edit:
If I modify something before the “cast to FireBreath” node (like removing the variable and adding it again) it runs but does not call the c++ function until the next engine restart. After the next restart it crashes on the cast node.
The FireBreathComponent is an UActorComponent, i try to get the Actor spawned by it.

Thanks for your answer.
Unfortunately I did not change anything on the c++ function recently.
There are some other weird behavior there, I modified my first comment.

Looks to me like you are not casting correctly, after you cast to GuarChar you already have access to all it’s content and then next node “cast to FireBreath” uses GuarChar component as the source object, which is not right , Cast is used to get reference to other objects (classes) , not variables and components directly. I don’t know what exactly you are doing here but you need to get a proper reference to CastToFireBreath. Hope this helps, Good luck and let me know.

The GuarChar has a FireBreath component, which is a ChildActorComponent.
I get the actor owned by that ChildActorComponent, and I cast that to “FireBreath” Actor. I think it should work like that.
(Even if it should not, the cast should not crash, it should fail I suppose :frowning: ).

Problem 1 (solved, my bad):

Actually the function call happened. The effect of the function was not visible (character had full hp, and the damage accidentally increased the Health instead of decreasing it). I placed a breakpoint to the function, but most likely the compiler decided to make an inline function from the function, so it never stopped there. I just placed a log message to the function and both the breakpoint and the log showed me that the function is actually called.

Problem 2 (work around):

Now I store a FireBreath Actor variable in the GuardChar class, initialized in the GuardChar’s begin play with the same cast. This way it does not crash.

I see, well my point was that you already got access(reference) to “FireBreath” after casting to GuarChar. And you’re right this would not cause the crash it would just fail to cast. Well I’m glad you got it working :smiley: !

Hey -

What does the FireBreath function do in code? Is it possible for you to post the header and source file for the code? Does the crash happen anytime you use a “Cast to FireBreath” node or only at certain times inside certain blueprints? Additionally could you post the log files from the crash to help identify what the cause is?

Cheers

Hello!

Thank you for your interest!

FireBreath was a blueprint class with a particle system.

I tried to reproduce the bug, but I could not :confused: Now I cast it outside of GuarChar again, but it does not crash anymore.

If I have some time I’ll checkout the buggy version from my repository, and check it again, and save the logs.

Hey -

Have you had the chance to check your older version for the crash? I will be marking this post as answered for tracking purposes however feel free to reopen it if there is any additional information you can provide that would help us investigate the crash.