edited September 19 in General Support
Heyhey,

I've subclassed a FloatValue_BaseType to effectively replace PlayerPrefs by FileBasedPlayerPrefs. As you can see below, its implementation is nigh-on identical to regular PlayerPrefs.

Everything works flawlessly during Play-In-Editor. However, the packaged build throws me a NullReference, even though FileBasedPlayerPrefs in general still function (schematic nodes et al.).

So I'm a bit stumped as to what could cause this, and would love some pointers on what I could check out.


Here's the script of the custom FloatValue_Type:

using UnityEngine;
using System.Collections.Generic;

namespace GamingIsLove.Makinom
{
[EditorSettingInfo("FBPP", "The value of a PlayerPrefs int or float variable.",
listName = "Variable/FBPP")]
public class FloatValue_FBPPType<T> : FloatValue_BaseType<T> where T : IObjectSelection, new()
{
[EditorHelp("PlayerPrefs Key", "The key (name) of the PlayerPrefs that contains the value.", "")]
[EditorInfo(isVariableField = true)]
[EditorHide]
[EditorWidth(true, hideName = true, noHorizontal = true)]
public string playerPrefsKey = "";

[EditorHelp("Is Int", "The value will be taken from an Integer PlayerPrefs (using GetInt).\n" +
"If disabled, the value will be taken from a Float PlayerPrefs (using GetFloat).", "")]
public bool isInt = false;

public FloatValue_FBPPType()
{

}

public override bool NeedsCall
{
get { return false; }
}


/*
============================================================================
Value functions
============================================================================
*/
public override float GetValue(IDataCall call)
{
if (this.isInt)
{
return FBPP.GetInt(this.playerPrefsKey);
}
else
{
return FBPP.GetFloat(this.playerPrefsKey);
}
}


/*
============================================================================
Editor functions
============================================================================
*/
public override string ToString()
{
return this.playerPrefsKey;
}
}
}


And the Error:
NullReferenceException: Object reference not set to an instance of an object
at GamingIsLove.Makinom.FloatValue`1[T].GetValue (GamingIsLove.Makinom.IDataCall call) [0x00001] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.ChangeVariableBase`1[T].Change (GamingIsLove.Makinom.VariableHandler handler, GamingIsLove.Makinom.IDataCall call) [0x00153] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.ChangeVariableBase`1[T].Change (GamingIsLove.Makinom.IDataCall call, System.Collections.Generic.List`1[GamingIsLove.Makinom.VariableHandler]& handlers) [0x0001e] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.ChangeVariable`1[T].Change (GamingIsLove.Makinom.IDataCall call, System.Collections.Generic.List`1[GamingIsLove.Makinom.VariableHandler]& handlers) [0x0000f] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.VariableSetter`1[T].SetVariables (GamingIsLove.Makinom.IDataCall call) [0x00017] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Nodes.ChangeVariablesNode.Execute (GamingIsLove.Makinom.Schematics.Schematic schematic) [0x00001] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.ExecuteNextNode () [0x000d9] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.NodeFinished (System.Int32 next) [0x00058] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Nodes.SteamStats.Execute (GamingIsLove.Makinom.Schematics.Schematic schematic) [0x00091] in <dde7d9e5e0bd4052b0794f95d5ec44e7>:0
at GamingIsLove.Makinom.Schematics.Schematic.ExecuteNextNode () [0x000d9] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.NodeFinished (System.Int32 next) [0x00058] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.ExecuteNextNode () [0x0010f] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.NodeFinished (System.Int32 next) [0x00058] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Nodes.StartGameNode.Execute (GamingIsLove.Makinom.Schematics.Schematic schematic) [0x00013] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.ExecuteNextNode () [0x000d9] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.NodeFinished (System.Int32 next) [0x00058] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Nodes.ChangeMusicNode.Execute (GamingIsLove.Makinom.Schematics.Schematic schematic) [0x0000d] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.ExecuteNextNode () [0x000d9] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.NodeFinished (System.Int32 next) [0x00058] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.Schematics.Schematic.Tick () [0x001d2] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.MachineHandler+MachineUpdate.Tick () [0x0006b] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at (wrapper delegate-invoke) <Module>.invoke_void()
at GamingIsLove.Makinom.Maki.FireTick () [0x0001b] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0
at GamingIsLove.Makinom.MakinomHandler.Update () [0x00001] in <bd910418d8d8436c8c34d66bbb2d0dbd>:0

Post edited by Nory on
  • This is most likely due to code stripping in the built game, since the script itself isn't directly referenced anywhere. There's a setting for that in Unity's menu: Edit > Project Settings ... > Player

    The Managed Stripping Level setting pretty much at the bottom here handles this. Set it to Disabled, or if you use IL2CPP, use Minimal to prevent Unity from stripping custom code.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited September 19
    I took a look at the Managed Stripping Level and it was already set to disabled. I also tried using the [Preserve] Attribute, still leading to the same result.

    In the end, I spotted that I had mindlessly placed the script in an Editor subfolder. So you were absolutely right, the script did get excluded. After moving it, everything works perfectly now.

    Thank you once again for your invaluable help.
    Post edited by Nory on
  • Ah, yeah - stuff in Editor folders are always stipped :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.