Function not working in BeginPlay()

Hello,
Why does ToggleTraceCheck(true); Function not work in c++ when its working from blueprints
AProjectXWeapon Derived BP Blueprints:

AProjectXWeapon::BeginPlay():
Skærmbillede 2022-02-09 115535

AProjectXWeapon.h

AProjectXWeapon.cpp

Define “not working”? What is it suppose to do? What’s happening? There’s quite a lack of information in your question

The ToggleTraceCheck is a function that turns on or off tracers. When i turn on tracers in the blueprint with the “Trace” bool the tracers are showing up. But if i try to do the same in c++ in BeginPlay() the tracers are not showing up. Is ToggleTraceCheck(true) not the same as the blueprint node in picture 1?

No, it’s the same. So would need more information to be able to help you further.

I have updated the first post. What more information/screenshot do u need? If the exact same thing is working in blueprints why would it not work in c++? i have not setup anything else in the event graph of the blueprint noir changed any code in c++, the tracers just shows up when i turn on the booleon in the blueprint, so ToggleTraceCheck(true); in c++ should be the only thing preventing it from working. The function is public.

I think I might have misunderstood. When you said working in blueprint, you mean calling the C++ function from the BP’s BeginPlay event? I assumed you meant a blueprint implement of the C++ function

Yes i am using the blueprint BeginPlay() to call the c++ function, I only used the UFUNCTION macro because i didnt know how to the implement the equivalent in c++ as the “ToggleTraceCheck(true);” didnt work, i dont need it to be blueprintcallabe and will remove it later. I want to delete that blueprint event now and have exactly the same setup in c++ so i can use “ToggleTraceCheck(true);” to turn on/off tracers in animations that i have setup in c++. So i cant use the blueprint event anymore
AProject_XCharacter.cpp - With the Animation setup, But the tracers dosnt get turned on/off with this and idk why. CurrentWeapon is a pointer to AProjectXWeapon.

Just to be super clear, and that’s working? But removing that call in BP stops it working?

This part is the reason why I’m asked the previous question. As you wouldn’t be able to call that from BP without the macro. So if you meant that you implemented what you did in BP (i.e. not what I described above) could you show the BP implementation?


What logs are getting printed?

Yes its working in blueprint, the tracers are showing up when i use the blueprint node in picture 1, but i want to set it up exclusively in c++ only like i tried in picture 2, as i need it to turn on/off the tracers from the animations code in character.cpp. Im only asking what is wrong with my c++ code method in picture 2 in my AProjectXWeapon::BeginPlay(), why does that c++ code not turn on the tracers when i start the game? Like it does when i use the blueprint method in picture 1

Picture 1:

Picture 2:
Skærmbillede 2022-02-09 115535

That’s really strange as that should be equivalent (also why I double checked I understood you correctly).

Have you tried adding additional logs? Is that even being called? Is everything getting the right values?

Idk how to debug it and the game also crashes when i toggle off “toggle trace check” to false in blueprints, but i bypassed it by creating an additional boolean and using the blueprint method to turn it on/off.

Now I’m confused again, you said that what you had was working. I asked if what you had in the screenshot showing blueprint code was working, i.e. in this picture

https://community.gamedev.tv/uploads/db2322/original/3X/c/c/ccaa933b3cd68a03358a9708ff9d115e38880ad2.png

And you said yes. But call it from C++ instead failed i.e.

void AProject_XWeapon::BeginPlay()
{
    Super::BeginPlay();
    ToggleTraceCheck(true);
}

Was not working. But now it seems you’re implying that the first screenshot was in fact not working.

Yes the blueprint method is working and the call from c++ is not. I was implying that the blueprint wasnt working because i needed it to work with my AProjectXCharacter::AttackLeft() so whenever a animation was played it would toggle on/off. I then found a way to tempoarily use the blueprint method which is, by adding an additional booleon “BIsTracing” in my AttackLeft() to toggle on/off the tracers and then using it with the blueprint method in my AttackLeft.

The c++ method also seems to be working now when im using the class/name specifiers AProject_XWeapon::ToggleTraceCheck(true); Thanks for the help, it helps me alot when im stuck :smiley:

I see, sorry for my constant confusion. :sweat_smile:

That would suggest it was calling a different function before. Do you have another function called ToggleTraceCheck?

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.