question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add preprocessor define symbols to Unity builder

See original GitHub issue

Context

Basically, we have a few preprocessor macros that we use and it looks like there isn’t an easy way of doing that without creating a custom builder. However, I think being able to specify custom defined symbols via yaml would be really nice!

So I was thinking something like this

defines:
    - STEAM

I can implement this, if this is something you’d think would be worth having.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pearcemichalcommented, Jun 5, 2022

I got it working, I will post the process here for anyone else that comes across this:

first, I set up my project to use a custom build script by following the steps in the documentation here: https://game.ci/docs/github/builder

relevant sections are buildMethod and customParameters

after copying the supplied template buldMethod.cs file into the Assets/Editor/UnityBuilderAction folder, in the GetValidatedOptions() method, I added the following if statement:

if (validatedOptions.TryGetValue("DEMO", out string _))
{
    string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup ( EditorUserBuildSettings.selectedBuildTargetGroup );
    definesString += ";DEMO";
    PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, definesString);
}

this will look for a customParameters -DEMO, and if it finds it, it will add it to the scripting defines list.

the yml code:

with:
    targetPlatform: StandaloneWindows64
    buildName: debris_field_demo_PC
    buildsPath: demo
    versioning: Semantic
    buildMethod: UnityBuilderAction.BuildScript.Build
    customParameters: -DEMO
0reactions
pearcemichalcommented, Jun 5, 2022

in the past, I used the scripting defines to create separate release and demo builds for my game. based on the description of the customParameters, I thought something like customParameters: -DEMO would work, but based on my testing it does not.

I do not understand what the stated solution to this is. could you please describe the process in more detail? (or add it to the documentation somewhere, for future reference)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scripting Define Symbols - Access in code? - Unity Forum
Download the Script or Copy/Paste it from the Below · Open Script · Go to Symbols property and add your own symbols ·...
Read more >
How to Manage Scripting Define Symbols in Unity - YouTube
Unity Asset Store: http://u3d.as/DgHWhen creating a game or an app for multiple platforms you may find yourself needing an efficient ...
Read more >
Custom scripting symbols - Unity - Manual
You can add and remove your own custom scripting symbols to the Scripting Define Symbols list by using the + and - buttons,...
Read more >
Short Unity tip: conditional compilation with custom ...
Short Unity tip: conditional compilation with custom preprocessor directives · First, you click File/Build Settings (or CTRL+SHIFT+B, as I ...
Read more >
Unity3D - Don't compile if package name doesn't exist
Preprocessors are not an invention of Unity but is a c# thing. ... package in your project add these defines to the Scripting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found