Hello, apologies if I don’t explain this 100% accurately. Basically, I have a C++ Object class, it’s supposed to be an item with values such as : weight, durability etc.
I want to give this Object a mesh and be able to spawn it in the world. I know you can’t spawn the Object type in the world and would need an Actor to do so, my question is, how can I make an actor derived from my Object item class which I could spawn into the world?
It has to be derived from AActor class. Only Actors can be spawned.
I understand what you are trying to do and seems like you are little perplexed, I had suffered from this situation once at past. Its good you to have such design and its great way but :
What you 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
- Installments etc etc.
What your SpawnableWeaponActor will have is :
- Static Mesh component
So basically, you will fetch, static mesh from your WeaponItem in constructor and summon at world.
Think UObject as datatype and keep it as it is. I hope it helps.
What you explained is somehow the same idea of using UPrimaryDataAsset within Asset Manager
Asset manager by tom looman
Asset Manager UE4 documentation
Thank you for both replies, how would I go about making UObject an attribute to the actor class? Making it a child wouldn’t work since it wouldn’t be an actor and nothing else comes to mind. Thank you!
U using c++ right ? Just expand general class list at c++ file generator wizard at UI and select AActor class. And import “[YourUObject].h” and refer to it.
If you find answer helps you, dont forget to upvote and mark as answer. It motivates people a lot because they are spending time for you.
If you want to access from C++, careful about
If you want to access them from Blueprint, please be sure that u are using UPROPERTY and expose your variable by EditAnywhere, BlueprintReadOnly etc…
Good examples here
Hello! Yes, C++, I did this and the compile part worked out without issues but when I tried accessing properties such as weight, ammo and so on they failed to compile, thanks again!
Thank you for the help ctndev!