- Home /
[Visual effects graph] How to write custom VFX Blocks ? (the proper way)
Just tried out the VFX Graph system, and it's awesome. I looked into the sources to find out how to extend it and write my own blocks, it appears that the system is looking at all files and finding out on its own which classes are VFXBlocks. I copied the Gravity Force Block and renamed it to Gravity2 and it just worked (I had to copy the .meta file and change the uid number as well).
The problem is you don't want to have to put files there to add new forces. Problem is, when I tried copying the Gravity2.cs file in my Assets folder, I got compilation error about protection level.
So my question is : is it possible to write custom VFXBlock child classes outside of the package folder ?
Answer by timpernagel · Jun 12, 2019 at 12:24 PM
Hey @Ben-Kuper, did you figured out the best approach to this? To be honest, I'm already struggling finding the "origin" *.cs file. Only finding the one which seems to be generated on every recompilation in the packagecache. Copying files there, f.e. Gravity, will be deleted after every compilation...
Update: After some research, I figured it out. For everyone who is interested: I had to clone the git-repo, switched to the branch which is working with my Unity-version and referenced the repo in the project-manifest like this: https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/master/TestProjects/HDRP_Tests/Packages/manifest.json
Answer by Flannelot · Jun 13, 2020 at 03:08 PM
I know this is an old thread, but thanks for the tip, and I wanted to add, if you copy the entire com.unity.visualeffectgraph@7.x.x package from Library/PackageCache into your own project package folder, Unity replaces the original package with your copy and marks it "in development" when you restart Unity.
You can then edit any of the package contents, I was able to create by own MagneticFieldForce in the Editor/Models/Blocks.. folder simply by copying the original VectorFieldForce and renaming the class and labels. It then works perfectly in the VFX graph interface.
It would be useful if Unity could implement a way of making custom blocks such as these without cloning the whole package, but its not too hard to do. It will just become difficult to maintain with updates.