Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example for setting preprocessor macros #473

Closed
efarraro opened this issue Aug 10, 2024 · 4 comments
Closed

Add an example for setting preprocessor macros #473

efarraro opened this issue Aug 10, 2024 · 4 comments

Comments

@efarraro
Copy link
Contributor

efarraro commented Aug 10, 2024

Context

Sometimes you want to include a preprocessor macro in your build (eg: #ANDROID, #DEMO, etc... ) in order to change what gets compiled into the build. Unity supports this behavior in the editor.

Suggested solution

Add the following example outlined here as an example in the 'Builder' section of the official wiki: game-ci/unity-builder#207

(Credit to @xwipeoutx for posting the following solution)

steps:
  - name: Apply csc.rsp (pre-processor symbols)
    run: echo -define:MY_SYMBOL >> Assets/csc.rsp

You will get warnings about "unapplied changes" - you could get around this by putting csc.rsp in your .gitignore, or allowing dirty build.

with:
  # ...
  allowDirtyBuild: true

Now in your code you can just do this:

void Start() {
#if MY_SYMBOL
  GetComponent<TMP_Text>().text = "I have a symbol!";
#else
  GetComponent<TMP_Text>().text = "I do not have a symbol...";
#endif
}

See Unity docs for the inspiration - under the heading "Setting scripting symbols via an asset file"

Originally posted by @xwipeoutx in game-ci/unity-builder#207 (comment)

@webbertakken
Copy link
Member

Accepting PRs.

We will not suggest using a dirty build if you can simply ignore that file. The dirty check is there to ensure no files were accidentially changed during or after checkout and would effectively be disabled by this measure. The docs should therefor not suggest using allowDirtyBuild for this purpose.

@webbertakken
Copy link
Member

cc @xwipeoutx

@efarraro
Copy link
Contributor Author

I still need to run yarn / test my changes locally, but I put up an initial PR and would appreciate any feedback, to make sure this is on the right track #474

@davidmfinol
Copy link
Member

Merged #474 so closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants