I have an Inventory Component, that works fine. My only Problem is, that I want to use the Inventory from the Parent on 2 Children (so that the Children just use the Component of the Parent, instead of there own).
Is there an easy way to do this? It is also only Singleplayer.
Inherited elements are hidden by default, you can show them like so:
If the variables on the components are flagged as Instance Editable, the children will be able to tweak them.
Even though they are hidden, you can still access them from the right-click graph menu.
When I use that Component I see then, it still says it is owned by the Child and acts as a completely independent inventory.
What I need, is that the Child simply just uses the Component of the Parent.
Because it is an independent inventory - that’s the whole point of inheritance. The child creates an instance of the component with the defaults present in the parent (or in the components).
If you want to the child to have access to parent’s defaults:
If you want the child to have access to the a specific parent’s instance’s data - pass on the appropriate reference.
I get that components normally are Independent and thats how I need it for 99% of the project. It is just that I switch between 2 Pawns and these 2 should use the exact same Inventory. So when the currently controlled changes something, it changes for the other too and vice versa.
[edited to avoid confusion] Create a function in the parent and call in the child. Like so:
If I understand this correctly, this would only allow me to access the parents Inventory, but not really use it (like if I loot something with the other pawn, it would still go into its separate (till then “cloned”) inventory?
Also it would make all UI things work only on its own Inventory as well?
Is there really no way, to just force the Component to legally use the Data of the Parent? Like each Component has a unique name in the Property Matrix, so shouldn’t there be an easy way?
Also I appreciate your help very much :).
//edit: Well I could also copy the inventory back and forth (with your Function). But that sounds like a potential bug hazard.
You can always pass references directly:
The child has an Instance Editable variable of the appropriate component type, the var is Exposed on Spawn.
It seems to me this is not really about inheritance rather than a semantic child-parent relationship between two completely seperate pawns, no? Or maybe it is too, but it’s still two seperate pawns that should access the same inventory component of one of them?
I’d either try and move the inventory to the player controller and make both access this instead, or access the inventory over a function only and override the function in the child so it uses the parent’s inventory (you’d still need a reference to the parent which is very similar to what Everynone suggested).
I think OP has something more advanced in mind than a sharing a single inventory. I think his/her actors each have an inventory and their descendants need direct access to it.
I originally wanted to to chip in as I have a somewhat similar system working on my end.
There is an inventory actor component and its children that act as extensions, bringing additional functionality. In this case the extensions do not need do have their own inventories even though they all share a base class. It’s complicated ;p
But the more I think about it, the less sure I am regarding what the end goal is and perhaps it is matter of semantics and I’m overthinking it.
I just glued it all up with Dispatchers so I do not need to rely on hard references.
Nice of you to overestimate my goals, but I really just need the other to use the inventory of the parent.
Also I am rather new to this Blueprint stuff, so sometimes I still think of stuff “this should be easy” (and then it isn’t, while other stuff is the opposite lol)
If you need just that - use a direct reference. Essentially treat the parent and child as 2 independent entities. Give the child reference to the parent and that’s it. As in the pic I attached somewhere below.
You can also look into Child Actors Components at some point - it’s a component that spawns an entire actor. Since the component must have an owner, the coupling between the two always exists.
So you end up with a physical hierarchy:
- [Child Actor Component]
This way the actor owned by the component can look up in the hierarchy and see if there’s a parent.
Well, I did it now the “copy” over to the Children (and back to the Parent), with each character Switch.
Thanks for all your help!