Are Nested Prefabs supported?

Options
So I'm not sure if what I'm looking at this for even the right solution for my situation, so I'll describe what I'm even trying to do.

My game is designed in a modular component-based architecture where the player's prefab is basically just a container that has no function, and contains a collection of prefabs that are each responsible for a single feature that the player is able to use.
Each of these features are defined as a standalone prefab, and then these prefabs get nested into the player's collection of feature, allowing you to modularly change the feature-set of the player at runtime.
aSqYjMy.png

I have a Bolt Entity on the top level of the Player prefab to control the position for example.
The problem is that from what I've seen, I can't add multiple State types to the same Entity, and I can't add 2 Entity components to the same prefab.
I can obviously add a Bolt Entity to each of the feature prefabs, but I'm wondering if used these prefabs in a nested way as in the picture above would work.
From the look of it, the Prefab Id is persisted and isn't shown as -1 as would happen when normally adding a second Bolt Entity to the prefab, but running this seems to not be able to call any of the EntityBehaviour methods such as Attached().
I made sure to compile the assemblies.

So at this point I'm not sure if I'm doing something wrong, or if the Nested Prefab use case is not even supported at all.
If it's not, what would normally be the way to handle modular entities that need to be each networked separately?

Thanks,
Mor

Comments

  • Paximillian
    edited July 2020
    Options
    So I think I have some answers for myself, but not sure if they're correct.

    From everything I can see, nested prefabs aren't allowed because of the simple requirement that BoltEntities must be at hierarchy root level.

    I did find a way to work with my generic ability data objects using an array of ProtocolTokens.
    Each feature attached to my player prefab is a class inheriting a common polymorphic base class, which means that I couldn't use a Bolt Asset that was set to an array of any of the built in types, including object, since the structure of the object properties are different between features.
    ProtocolTokens are basically a way to freely serialize data, and works with types implementing the IProtocolToken interface, of which an array can be made as a Bolt Asset property, meaning it can support polymorphism.

    I was able to register and listen to callbacks of individual features on the player prefab in this way and it worked perfectly.

    My problem right now is about modularly adding and removing features at runtime. Specifically adding.

    The problem is that when I instantiate a new object and child it to the player entity, even on the owner instance of it, its EntityBehaviour methods are never run (Attached, SimulateOwner, etc).
    That's when using the native Unity Instantiate method, since BoltNetwork.Instantiate can only be used on BoltEntities, which this prefab CAN'T be, since its purpose is to be childed to another entity.

    So my question now is, how exactly do I get objects that were dynamically added to the synced entity to receive entity network callbacks?


    EDIT:
    Just found out about BoltEntity.SetParent() which invalidates this entire post.
    So it's actually possible to use BoltNetwork.Instantiate along with entity.SetParent() to handle nested prefabs that are dynamically added to the entity.
    The set parent doesn't seem to be a networked call though, so it needs to be used on all instances for it to work.