Skip to content

ref: Support Unity as a platfom #4322

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Sentry/Platforms/Unity/Sentry.Unity.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<!-- To be able to make the internals visible, since we're not signing the assembly for Unity -->
<SignAssembly>false</SignAssembly>
<DefineConstants>$(DefineConstants);SENTRY_UNITY</DefineConstants>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="Sentry.Unity" />
<InternalsVisibleTo Include="Sentry.Unity.Tests" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions src/Sentry/Platforms/Unity/SentrySdk.Unity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#if SENTRY_UNITY

namespace Sentry;

/// <summary>
/// Internal Sentry SDK entrypoint.
/// </summary>
/// <remarks>
/// This class is now internal. Use <c>Sentry.Unity.SentrySdk</c> instead.
/// <para>
/// To migrate your code:
/// <list type="number">
/// <item>Change <c>using Sentry;</c> to <c>using Sentry.Unity;</c></item>
/// <item>Keep using the <c>SentrySdk</c> API itself - no changes needed to method calls</item>
/// <item>Add <c>using Sentry;</c> if you need access to types like <c>SentryId</c>, <c>SentryLevel</c>, etc.</item>
/// </list>
/// </para>
/// </remarks>
Comment on lines +5 to +18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only visible to Unity SDK users. The changes here are part of breaking changes to the Unity SDK and this aims to reduce friction when migrating.

internal static partial class SentrySdk;

#endif
16 changes: 3 additions & 13 deletions src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,19 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(SolutionName)' != 'Sentry.Unity'">
<PropertyGroup>
Copy link
Contributor Author

@bitsandfoxes bitsandfoxes Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to conditionally set the TF, they get overwritten by the platform .props on line 4.

<TargetFrameworks>net9.0;net8.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks Condition="'$(NO_ANDROID)' == ''">$(TargetFrameworks);net9.0-android35.0;net8.0-android34.0</TargetFrameworks>
<TargetFrameworks Condition="'$(NO_IOS)' == '' And $([MSBuild]::IsOSPlatform('OSX'))">$(TargetFrameworks);net9.0-ios18.0;net8.0-ios17.0</TargetFrameworks>
<TargetFrameworks Condition="'$(NO_MACCATALYST)' == '' And $([MSBuild]::IsOSPlatform('OSX'))">$(TargetFrameworks);net9.0-maccatalyst18.0;net8.0-maccatalyst17.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(SolutionName)' == 'Sentry.Unity'">
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<!-- To be able to make the internals visible, since we're not signing the assembly for Unity -->
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<ItemGroup Condition="'$(SolutionName)' == 'Sentry.Unity'">
<InternalsVisibleTo Include="Sentry.Unity" />
<InternalsVisibleTo Include="Sentry.Unity.Tests" />
</ItemGroup>


<!-- Platform-specific props included here -->
<Import Project="Platforms\Android\Sentry.Android.props" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
<Import Project="Platforms\Cocoa\Sentry.Cocoa.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
<Import Project="Platforms\Native\Sentry.Native.targets"
Condition="'$(TargetPlatformIdentifier)' != 'android' and '$(TargetPlatformIdentifier)' != 'ios' and '$(TargetPlatformIdentifier)' != 'maccatalyst'"/>
<Import Project="Platforms\Unity\Sentry.Unity.props" Condition="'$(SolutionName)' == 'Sentry.Unity'"/>

<PropertyGroup Condition="'$(EnableAot)' == 'true'">
<IsAotCompatible>true</IsAotCompatible>
Expand Down
5 changes: 4 additions & 1 deletion src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Sentry;

#if !SENTRY_UNITY
/// <summary>
/// Sentry SDK entrypoint.
/// </summary>
Expand All @@ -14,7 +15,9 @@ namespace Sentry;
/// It allows safe static access to a client and scope management.
/// When the SDK is uninitialized, calls to this class result in no-op so no callbacks are invoked.
/// </remarks>
public static partial class SentrySdk
public
#endif
static partial class SentrySdk
{
internal static IHub CurrentHub = DisabledHub.Instance;

Expand Down
Loading