How do I create AActor child from UObject

Hi,

I want to create a AActor from UObject class.

Here is my hierarchy.

Item(UObject C++) → UtilityItem(UObject C++) → Flashlight(AActor Blueprint)

How do I manage this?



–edit–

Since my question is not very well explained I will go over an example.

My Item abstract class have some general members like, item text, item thumbnail, item pickupmesh etc.

Also have function OnUse

And have derivatived classes UtilityItem, ConsumableItem which are implementation of OnUse function. At the end I have more special itemset.

UtilityItem distinguish in two Key, Flashlight object

Consumable Items are Food, Flask etc

What I want to achieve at the end use PickUpMesh as a PickUpMesh of an object in the world, thats why I need an AActor.

I don’t fully understand what you are trying to do.
Is this a class hierarchy or are those variables inside of each class?
Do you want to construct new AActor object inside some other UObject class or evolve your UObject to AActor?

You approach doesn’t really make sense. You can’t create a child of a class from the parent of the class you want to make a child from. I think that’s what you’ve asked for.

Check out the hierarchy from here:

Making UtilityItem an AActor makes sense to me. There will be a lot of actor base class functionality that will belong in there.

For my object view its
Item(Base) → Utility Item (Child) → Flashlight (Child)

Actually parent and child relation,
AActor is the child of UObject

So what is not logical? Why its not making any sense?

Dear Noowai, its class hierarchy on my theory. At the end I wanted to evolve UObject to AActor. To be more specific I will edit question.

I’m sorry I’m struggling to understand your structure and what you’re actually asking for by “How do I manage this?” and “What I want to achieve at the end use PickUpMesh as a PickUpMesh of an object in the world, thats why I need an AActor.”.

Issues I see:

  • Item(UObject C++) can’t have an static mesh component. I’m pretty certain that needs to be part of the actor.

  • Structure seems overly complicated

  • It’s quite rare to inherit UObject directly. The only use case I know of is to create a new Asset Type. You could use it for the item base class but I don’t see the point.

If I understand correctly you want the functionality of OnUse to work differently between items. Some items you consume (eat food) other items (utility items) you interact with - turn on flash light. Items themselves can be quite different.

I think Interfaces could give you the flexibility you need: Interfaces | Unreal Engine Documentation

Assuming I’m understanding this… This is how I’d approach this.

You could do this easily if you simplify things using an interface for OnUse

AItemBase : public AActor (name, icon, static mesh, basic state) IMPLEMENTS Interface OnUse

Flashlight : public AItem (OnUse turns on light)

Food : public AItem (OnUse gives health)

Then for other items that don’t fall under that hierarchy…

AWeaponBase : public AActor Implements (OnUse fires weapon)

ARobotBase : public ASkeletalMeshActor (OnUse repairs broken item)

Item class shouldnt be AActor, its should be UObject, its abstract class, your approach is not right. If you use AActor for Item abstract class, you cannot control complex item system. It makes code over complicated with some unnecessary items. I could make it AActor from beginning but I didnt I want to learn on way that I describe.

No worries. I still have no idea what you’re asking help with. Is OnUse the pure virtual function?
I think the language barrier is making this tricky. Hopefully someone else can help you.

I’m not fully sure of what you trying to accomplish, but:
AActor class is already child of UObject class. And since your class is child of UObject, you cannot use AActor features in it. Unless you duplicate the code from AActor or use double inheritance from it (which is a bad idea).

edit: If I understand correctly, you need to pickup different objects in game with the same call. Since you need a placeable object in the game it is going to be AActor. Your Item could be just a data structure with all those parameters you described. Using an interface will help you to decouple and use the same PickUp call for everything.

import akka.actor._
class RootActor extends Actor{
def receive = {
case msg:String => println(msg+" “+self.path.name);
var childActor = context.actorOf(Props[Child],“Child”);
childActor ! " Hello”
}
}
MyPrepaidCenter

I also want to create an object about gardening but how can’t understand,
I want to create an object of the best tomato planter found online.

What was I need to do is create an independent actor class (get away thought that this actor has to be its child!) which has UObject as an attribute and you can spawn everywhere that actor class.
Lets imagine we have WeaponItem as UObject. What does that item as UObject?

  • Ammo Clip
  • Static Mesh
  • Thumbnail
  • Ammo
  • Installments

What your SpawnableWeaponActor will have is :

  • Static Mesh component
  • WeaponItem