Hi All,
First post here hopefully I don’t mess this up, any help would be greatly appreciated!
I’m really struggling with how I should properly reference a BP Actor class I’ve created, here is the situation.
I have an Air Hockey game I’m practising on and I have created a BP class derived from the Actor class, this BP class houses the 'Puck" for the game. I had also created a “Striker” (The thing to hit the puck) as a BP class derived from the Actor class. Within BP the Striker would look for all classes of type “Puck” and update the position, and this works as expected. However, because this is happening on every tick I thought I’d try to place it into a CPP function instead to make it more efficient.
This is where the problems began, I started by recreating the Striker & Puck classes into custom CPP classes derived from Actor. Then in editor, I create a BP derived class from the CPP classes.
In the Striker.CPP I need to be able to reference the Puck, so it can get its position and update its own position accordingly. This is what I’ve tried, in the Striker.h file, keeping in mind I’m exposing these through UProperty so I can assign the reference from the BP derived class.
AActor* Puck;
- This does not allow me to select the BP_Puck in the BP editor
TSubclassOf<AActor> Puck;
- This allows me to reference the BP_Puck correctly, but then I can’t seem to use the reference at all as it returns UClass. I.e. in the Striker.CPP I try to obtain Puck->GetTransform().GetLocation();
but it the UClass does not contain this property.
APuck* Puck
- This correctly lists the BP class in editor but does not allow me to actually click on it, the box just stays empty as if it’s not a valid reference even though it returns only that one class.
I think I’ve searched every forum post I can at this stage and I’m guessing I’m going about this the wrong way, but I can’t figure out how you’re supposed to achieve this. From my understanding, blueprints are meant to be a good starting and prototyping place, then transition to CPP implementation as required for performance.
But I can’t figure how you can possibly reference any object in your scene that is a BP derived class. Which from my understanding this is relatively common, to create a CPP base class then derive BP classes to alter meshes and what not? Am I going about this completely wrong or have I just missed something, all I need to be able to do is create a reference to a BP class in my header so I can interact with it accordingly in-game.
Appreciate any help on this one!