If you need to have replicated entities you need to create either a ghost prefab and use baking (in sub scene) or use runtime ghost creation (so via GhostPrefabCreation.ConvertToGhostPrefab).
Either work and result in replicated entities.
Of course there will be structural changes, we are adding components, so no matter what you are doing, you need to be careful to no keep any buffer or lookup (or they will be invalidated). If the error due to structural changes comes from calling the API itself, please report that to us, because this should not be the case.
That being said, I think what you need in this case is only the “visual” part of the ghost, so that user see where it is placing it. You provably don’t need anything else (in terms of components).
If that is true one option would be to spit the graphics information in a child entity like:
root (ghost)
graphics .. (no replicated components)
and when you need to spawn it for that purpose, you just need to grab the graphic entity (linked entity group entry 1 for example) and instantiate that.
When you are done, destroy it and replicate with the ghost instance.
if you need to keep both “full” prefabs (not replicated and replicated) either you do at baking time (you create both, but you said is not an option) or, yes, you need to remove all the components that make a ghost “a ghost”,
Among the one you listed only these one are the one that should be pretty much removed. And I suspect only the client needs to do that (server does not).
[LIST=1]
[*]ecb.RemoveComponent<GhostInstance>(entity);
[*]ecb.RemoveComponent<PredictedGhost>(entity);
[*]ecb.RemoveComponent<PreSpawnedGhostIndex>(entity);
[*]ecb.RemoveComponent<SubSceneGhostComponentHash>(entity);
[/LIST]
Without theses, none of the ghost systems would run (all queries pretty much depend on these). But this is just a “structural” change optimization. Ah the end of the day you need to do that.
Please don’t remove the Simulate tag, it is assumed to be present on all entities.
Honestly the easiest is still to do the work once when you import the prefab and create at that point (at runtime) the “non-ghost” variant. At the end, you still need to have them anyway because user place building all the time. So instantiating and then cleaning up by removing components seems kinda a waste of time doing that multiple time.
At least caching the resulting “new” prefab makes sense to me.