How can I spawn a C++ class instance inside a Blueprint?

My goal is to create a “lake” blueprint that encapsulates everything and I’ve gotten pretty far so far and I’ve taken bits and pieces from various tutorials out there.

This is what the lake blueprint has in it’s component tree:

  1. Root: A billboard of a lake icon making it easier to select.
  2. Has a StaticMesh of a Shape_Plane with a material of “Gerstner Waves”
  3. Has a PostProcessComponent to handle underwater effect
  4. Has a Child Actor that points to a C++ class – Ocean Manager

The construction graph is responsible for:

  1. Disables Underwater effect by default.
  2. Use raytracing to calculate size of lake plane and size the plane accordingly.

The event graph is responsible for:

  1. Determining whether camera is underwater or not.

So far at this point, everything is grand. But the Ocean Manager class is responsible for determining the height of water at any given xy position in C++. The material duplicates this work in blueprint. So what I want to do is instantiate an instance of the Ocean Manager class owned by the lake blueprint and then use it to handle the camera underwater detection accurately as well as use it to handle buoyancy of other objects that will talk to it via reference. I’ve tried a number of approaches, but I’m totally open to the right way to do this.

This screenshot signifies the problem I’m having in the construction script. I can’t figure out how to get a Ocean Manager Class Reference to a Ocean Manager Reference. It feels weird because the cast to Ocean Manager makes it a class reference. My understanding is that the fact that it is a child actor, it is supposed to be automatically spawned – but I don’t really know what’s going on. Please help :slight_smile:

Nothing spawns automatically, it needs to be spawn with a call, there node for that “Spawn Actor From Class” for that. Blueprint class is no diffrent from C++ class, it’s bind with the same rules the way you think C++ class work the Blueprint class works the same way and object variable is a like empty pointer you need to populate it by spawning for example

If you Ocean Manager is extending from UObject, move it to AActor, because you can’t create UObject in blueprint

Sorry for delay. I was busy with other tasks but finally back to this problem. Originally I attempted to implement this via Spawn Actor, but I have the same connection problem. I’ve attached another screenshot of this approach.