Hi. For somewhat reason my pointer doesnt return the object that I want, even when it’s already setted. I have experience with C++ but I’m new to Unreal and have no Idea what is causing this.
AttackManager->GetDefaultObject<AAttackManager>()->...
With this line, you are modifying the CDO (class default object) and not the actual instance of the class. The CDO is basically the template of the class. You’ll be instancing (spawning/creating) your object from this template. Remove the GetDefaultObject part and it should work as expected.
Thanks for the reply. I made what you said but had no positive results. Actually forgot about PartyManager.h which holds the AttackManager reference as shown. It was a TSubClassObject, that’s why I had to use the GetDefaultObject so I’ve changed for a regular pointer to do what you sad but no avail . From the Attack Manager class I trigger the attack input and checks there the currentPlayerAtacking, but still getting null. The oddest thing is that the currentPlayerAttacking seems to be set properly.
Just to get this straight? Do you spawn the AttackManager anywhere? TSubClassOf just gives you a class. When spawning an object, it asks which class you want to spawn. Instead of hardcoding in a class, you can give it a TSubClassOf variable, so that it spawns the class that is set inside the TSubClassOf variable.
Spawn you mean placing it on the map?
I guess that I’m starting to realize my problem. I want to get the instance of that AttackManager class from the scene but maybe this just dont works, since C++ can’t see Blueprints. So that’s why I’m losing the currentPlayerAttacking reference between functions calls
I found the problem! I was selecting the blueprint class for the Attack Manager but I should have selected the original class in C ++. I thought Unreal would use the C ++ class directly even though using one in BP instead. Now I have a question: do I have to turn all my C ++ classes into BP to properly use them or can I just drag them onto the scene?
You don’t have to create a blueprint for every C++ class. Blueprints are classes as well. The difference is that instead of writing code, you are using a more visual approach to “code” it.