Prefabricator - Open Source Prefab Plugin

Thanks for the continued updates Ali. I’ll have a check next time I’m on that bit of my project and let you know if there are problems after updating the assets. :slight_smile:

I have recently found some spare time and got back to the project where I needed this functionality. I have modified [USER=“28980”]Ali Akbar[/USER]'s code in such a way that it now preserves the reference to the actors inside the prefab. Here is pretty much what I did:

  • I modified FPrefabricatorPropertyAssetMapping structure to store ItemID for the referenced actor (the ID is obtained from UPrefabricatorAssetUserData)
  • I store this ItemID inside UPrefabricatorProperty::SaveReferencedAssetValues()
  • I modified method FPrefabTools::LoadStateFromPrefabAsset such that it first spawns all the actors as placeholders and only restores their properties after all are spawned.
  • I take the list of spawned actors and forward it all the way to UPrefabricatorProperty::LoadReferencedAssetValues(TArray<AActor*> ChildActors)
  • Inside this method, I use the previously stored ItemID to identify the correct actor and change the ReferencedPath accordingly.

I am willing to share the code if anyone is interested (and if Ali agrees), but I have not yet tested it properly so I may have broken something else along the way.

If Ali is ok Im very interested in your code.

Thank you **Jan Byška. **

This is an open source project, you can do what ever you want with it :slight_smile:

I’d love to incorporate this into the plugin. You can share the code (preferably as a pull request in github) and I’ll test and integrate it

I’ve made some major performance improvements to prefabricator and I’ll push a new update tomorrow. It does the following:

  • Reduce the generation time of prefabs during creation and randomization. This is noticeable with larger nested prefab with thousands of children
  • Optimized the thumbnail Renderer. The thumbs are no longer realtime. They are instead rendered once and cached so this will not slow you editor down with larger prefabs

Good to hear about the performance improvements. :slight_smile:

I have cleaned up the code, updated it to the newest version and created two pull requests.

The first one is dealing with the local actor references. As I said before I use ItemID to lookup the correct actor when restoring the actor state. However, it is way from perfect/finished and I don’t think you want to pull it as is. The known limitations are:

  1. it does not support nested prefabs
  2. soft references are kept unchanged - but I consider this feature as it allows you to reference the same actor from all prefabs while hard references are prefab specific

The second pull request is dealing with another issue I have run into recently. If I try to spawn a huge amount of prefabs at runtime that contains components with collisions set to Query and Physics the game starts to choke and eats up all the memory. Upon investigations, I found out that all the components are spawned on top of each other which causes PhysX to deal with the overlaps when the component is registered (or at least I think so) and significantly slows down. Therefore, I have disabled serialization of RelativeLocation for root components. The relative location of the root component is redundant anyway as it equals to the actor location. Restoring the relative location will essentially put all spawned components (from different prefabs instances) on top of each other even if the prefabs are spawned at different places.

Both pull requests were tested separately and in combination on a limited number of prefabs in my project. It works for all of them but it may break something else, so please feel free to reject the pull requests. I just hope it will give you a starting point to improve the already very handy plugin.

Hi Ali,
I have found another bug (two closely related actually). It appears that changes made to properties of prefab actors are sometimes not stored nor propagated to the other prefabs already spawned in the editor. I have tested it mainly on the master branch, but I believe that it also appears in older versions.

The root of the problem of both bugs is that you are serializing only those properties that are different from class default object (CDO).

The first issue with this approach is that the user can set a different default value for the component variable inside an actor (e.g., true while CDO would have false). Then modify this value in an actor instance inside a prefab such that it is equal to the component CDO (i.e., false). In such a case, the value will not be serialized since HasDefaultValue method will return true. However, when spawning the prefab, the (wrong) default value from the actor (i.e., true) will be used. Therefore you need to use a CDO object of the component’s owner to retrieve the correct default values. This approach, however, works only for native C++ classes as the blueprint classes do not have a correct CDO available. Therefore, I spawn a copy of the actor and delete it later in such cases. Maybe you (or someone else) can point me towards a better solution for blueprint actors as I am not familiar with how exactly CDOs works in this case.

Now on the second problem. When you change a property of an actor inside a prefab from anything back to the default value, this change is not propagated to existing prefabs. The problem is that you are reusing existing actors in the spawned prefabs. Since the value is not stored (being the default one), this spawned actor will not be updated correctly. The solution I come up with is to change the actor PrefabItemID inside the ActorData array in case the actor was modified when saving the prefab. This forces the plugin not to reuse the existing actor if it was modified, and it spawns a new one instead.

Another straight forward (but perhaps suboptimal) solution would be setting HasDefaultValue to always return false.
I have created another pull request to your git with the modification described above if you are interested.

Thank you [USER=“117903”]Jan Byška[/USER] . I looked into the first bug but couldn’t get it into the next update (1.4.0) I’ll fix this in the next update. I’ll have a look at the second one too

I’ve submitted a new update. Lots of new improvements and bug fixes. It should show up in the marketplace in a few days

Version 1.4.0

  • Fix: Massive improvements to runtime prefab spawning. Spawn thousands of prefabs at runtime with minimal overhead
  • New: Procedural Platformer Level sample: Build a platformer level by assembling small building blocks and using those to build more complex nested prefabs, eventually building one nested layout prefab with thousands of valid playable layout randomizations. Video
  • New: Construction System - Enable your players to build their own worlds by assembling floors, walls, ramps corrdiors. There’s a game sample demonstrating this. Video
  • New: Rewrote the thumbnail renderer, drastically improving the performance. The thumbs are rendered and cached only while saving the prefab. This avoid performance issues in the content browser for larger prefabs where they were previously rendered on demand
  • New: Prefabs hold soft references to child prefab assets. This avoids breaking reference issues on child prefabs when their location was changed in the content browser
  • Fix: Fixed a crash issue when prefab settings were changed from other editor windows (like Dungeon Architect’s theme editor window)
  • Fix: Prefabricator loads correctly in custom viewports (like Dungeon Architect’s theme editor viewport)
  • Fix: Deep nested prefabs sometimes had their mobility incorrectly set to movable (when they were static). This also fixes the actor hierarchy unlinking issues where the actors were moved out of the prefab hierarchy
  • New: Added a new samples submodule under Content/Samples. All sample content reside in this submodule to avoid increasing the main code repository’s size
  • New: Prefab Randomizer actor has a delegate to notify when randomization finishes
  • Fix: Collision profiles are now saved correctly (Doesn’t work in some cases and is still an open issue)
  • New: Updated the prefab toolbar icon in the editor window and the prefab actor icon
  • New: Moved the documentation to sphinx-docs for cleaner organization and maintainance. Updated the docs with the new construction system feature. Link
  • New: Disabled Undo / Redo transactions on creating prefabs to improve performance while mass creating prefabs. This might be restored in the future versions

what can I say… 50 points for ravenclaw dude! :slight_smile:

[USER=“28980”]Ali Akbar[/USER] Wow. I just found this. You are amazing.

@timtimmy Thank you :slight_smile: Please consider joining our discord channel if you have any queries, we have an active community there: Code Respawn

Submitted a new update

Version 1.5.2

  • New: Added engine 4.25 support
  • New: Project settings has default thumbnail settings which will be used while saving the prefab asset

It should show up in the launcher in a few days

Grab this build (Win64) from github

Hello Ali, as an ex-Unity, new-Unreal user all i can tell is “your plugin is just a dream”. I cannot believe how this can be a free plugin!? … Thank you so much!

Thanks for the response, I checked this page Loading... and I’m not sure if this works anymore. The box just seems to follow the meshes when I move them, or it re-generates each time I move something. My prefabs are floating above the ground because the box extends too far below them and I have to manually lower the whole prefab.

Im trying to set prefabs along the spline(imagine fence, or street lights) Im trying to do it the same way I scatter static meshes. but it doesnt seems to work. Can you help me and point out to me what im doing wrong?

Hello, I’m using Git for version control. I added the plugin to the project plugins. I’m getting compilation error after cleaning the ignored files and recompiling the project. Prefabricator is causing the error. These two directories are in my ignored list:

Plugins//Binaries/
Plugins//Intermediate/

The gitignore file I use:
https://www.gitignore.io/api/windows…o,unrealengine

Error message:
… could not be compiled. Try rebuilding from source manually.

Environment setup:
Unreal Engine 4.25.1
Prefabricator 1.5.2
Windows 10 1909
Visual Studio 2019 16.6.2
MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.26)
Windows 10 SDK (10.0.18362.0)

Documentation indicates replication is supported. However when I spawn a prefab at runtime on the server (using the SpawnPrefab node), it is not replicated to the client(s). I’m testing with a simple prefab containing a single static mesh. Prefab asset has the “Replicates” boolean checked.
UE 4.25.1
Win10 x64

is this a bug or is there something I’m missing?
Thanks

Really appreciate giving this away for free. We have started to use this in some of our projects as an alternative to blueprints to use as containers.

We have found 1 issue currently which is quite a blocker for one of our projects.

Repro:
Spawn prefab at runtime that contains a blueprint that runs a timeline node, the timeline doesn’t work. (This is on multiple classes with things like platforms moving, visual effects being triggered via timeline and various other movements, none of them work).

It works if spawned in via editor, which made me think it was related to world context object, initially it was in the game mode with ‘self’ connected to it, I then proceeded to try it on various other locations but had no luck fixing the issue.

Would appreciate any insight into why this might be happening or even better, a bug fix for this particular issue.

Cheers!