Category:Unity V3

From PopcornFX
Revision as of 10:29, 28 January 2021 by JBilalte (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
! IMPORTANT ! This is a PopcornFX v1 page. PopcornFX v2 Unity plugin documentation can be found here

Our official thread on the Unity forums is here :
You can find the documentation for older versions of the plugin here


What's the PopcornFX Unity Plugin

The PopcornFX Unity plugin is an integration of the PopcornFX runtime libraries in the Unity game engine.
It takes advantage of Unity's Native Plugin Interface and Unity's command buffers.

The plugin actually refers to 2 distinct parts :

  • The native plugin: a C++ library that runs natively on each platform, libraries for each platform can be found in Assets/Plugins.
  • The managed plugin: a set of C# scripts that are not platform-specific and provide the interface between Unity and the native libraries. They're located in Assets/PopcornFX/Scripts/

These are both identified by their version numbers and can't be dissociated (you can't take the native part from the 3.0 plugin and use it with 3.1).
The Asset Store packages are identified with the managed version number only.

The managed scripts are provided with each version of the plugin (desktop, ios and android) and should be exactly the same (so once you've imported 3.0 from whatever package, you only strictly need the content of Assets/Plugins/ from the other packages).
All 3.0 packages have the same managed assemblies. Only the different platform-specific native libraries are exclusive to each package.

Getting Started

Setup From A New PopcornFX Project

  1. Make sure you are using the right version of the editor.
    The editor's version must match the PKFxRenderingPlugin component version.

  2. Create a new project and choose the 'Unity Project' template
    Set your project to be located in <Unity project's path>/YourFxProjectName

  3. Make effects!

  4. See Unity Project Setup and Use Particle Effects

Unity Project Setup

Importing for the first time / updating a project with v3.0+

  1. You only have to import the plugin package in your project

Updating a project with v2.X

  1. Make sure to upgrade your PopcornFX editor to the latest version (1.13.3) that you can download here and update your source PopcornFX project.
  2. Start by removing the folders "Assets/PopcornFX", "Assets/Resources/PackFx/" and also make sure to remove the old DLLs in "Assets/Plugins/PK-UnityPlugin*" before opening your project.
  3. Open your project and import the .unitypackage.
  4. The plugin now requires to enable unsafe code. You can add a file that contains just "-unsafe" in your assets folder and name it "smcs.rsp" ( as explained here ) or just enable it in Unity's player settings.
  5. Select the PkFXSettings.asset in the assets (it should be created when PopcornFX starts) and click on "Set Pack Fx Path" and select your PopcornFX project (where the PopcornProject.pkproj is located).
  6. Re-import the effects by clicking on "All" next to "Reimport Pack" or select which effects to import by clicking on "Choose files" (still in the PKFxSettings). make sure all the effects that are used in your projects are imported correctly.
  7. Right click on the project explorer in Unity and select PopcornFX > Update PKFX references, it should update all your scenes and prefabs so that they use the new PopcornFX component (this will keep all your attribute values and asset references).
  8. Make sure everything works fine in the editor.

The way to set the attributes and the samplers has also changed a bit. You now have to go through the PKFxFX.SetAttributeSafe (takes the name of the attribute and its value, check if the attribute exist and clamp the value) or PKFxFX.SetAttributeUnsafe (takes the attribute ID that you can retrieve on the asset by calling PKFxFxAsset.AttributeIdFromName and the attribute value, no clamp or check is done so be careful using this).

For the samplers, it works pretty much the same as before, the new function to set those is "PKFxFX.SetSamplerSafe".

How To...

Import Your Effects

In PopcornFX/Resources/PKFxSettings :

  • Set Source Path : Path of your Popcorn Project.
  • Set Destination Path : Path where you want your Effects to be in Unity.
PkFxSetting Overview

While Unity is open, It will automatically import and reimport effects located in the Pack Fx Path when they are updated.

  • This is triggered when saving inside PopcornFX editor
  • And also when updating your repository !

You can reimport manually :

  • Inside PKFxSetting, 'Reimport Pack' allows you to Import the whole pack, or to choose what effects to import.
PkFxSetting Importer
  • By selecting one effect asset and clicking the 'Reimport' button
PkFxEffect Inspector

Use Particle Effects

  1. In your scene add the PKFxCamera component to your camera. You should tag it as main camera.
  2. Add the PKFxRenderingPlugin component in your scene.
  3. Add a PKFxFX component
    • Either by creating a new GameObject
    UnityFXNew V3.gif
    • Or by adding the component on an existing GameObject :
    UnityFXAdd V3.gif
  4. Select a "PK Fx Fx Asset"
    UnityFXSelectAsset V3.gif
  5. Run, watch, enjoy.

Setup Particle Collisions

Setup Particle Collisions

Handle Events

Handle Events

Identify Errors (Debugging)

Identifying Errors

Animate Effect Attributes

Animating Effects Attributes

Animate Effect Attribute Samplers

Animating Effects Attribute Samplers

Manage Effects' Assets Loading

Managing FX Loading

Setup Sound Layers

Setting Up Sound Layers

Pass Custom Data to the Audio Samplers

Passing Custom Data to the Audio Samplers (Unity Plugin)

Components Reference


PKFx-Helper Assembly


PKFx-Runtime Assembly


PKFxManager Assembly

Plugin's Menus




Feature list

Not all features allowed by the PopcornFX SDK are implemented in the Unity plugin.
To see the current status of the Unity integration, see the Feature list.