#archived-code-advanced
1 messages · Page 101 of 1
Hello, my mesh is not generating if there are objects on top of them, what can I do? I am new to working with nav mesh so I am confused.
This depends on your agent's height
You might have set the height too tall so navmesh does not get generated there
Hey guys, I've been looking at implementing some UI and I got some doubts
I see some people saying i just have only 1 canvas, other people saying i should separate Ui elements inside their own canvas.
My problem atm is that i want my mobs to have health bars and also show damage numbers on screen, i feel like the best solution would be get all of thay centralised into one world space canvas as that will be redrawn quite a lot anyway and have common HUD elements in their own canvas, in a separate scene
How does that sound?
nice one, thank you!
Hey another small issue sometimes the same prefab isnt generating completely the nav mesh, as you can see there part of it is empty any ideas?
Looks like your mesh has holes
So what you’d want is setting up proper collider rather than just using mesh itself
BoxCollider seems like better fit in your case
Yeah thats what I tried, it worked thanks again!
Any idea why my load is loading my camera below my player?
public void SaveGame()
{
int money = FindObjectOfType<MoneyManager>().currentMoney;
GameObject playerGameObject = GameObject.FindGameObjectWithTag("Player");
if (playerGameObject != null)
{
Vector3 playerPosition = playerGameObject.transform.position;
Debug.Log("Saving game. Player position: " + playerPosition);
SaveManager.instance.SaveGame(money, playerGameObject, playerPosition);
}
else
{
Debug.LogError("Player GameObject not found. Make sure it has the correct tag.");
}
}
void Start()
{
// Load saved data
SaveData data = SaveManager.instance.LoadGame();
if (data != null)
{
FindObjectOfType<MoneyManager>().currentMoney = data.money;
Debug.Log("Loaded player position: " + data.playerPosition.ToVector3());
GameObject playerGameObject = GameObject.FindGameObjectWithTag("Player");
if (playerGameObject != null)
{
SaveManager.instance.LoadPlayerPosition(playerGameObject, data.playerPosition);
}
else
{
Debug.LogError("Player GameObject not found. Make sure it has the correct tag.");
}
}
else
{
Debug.LogWarning("No save data found. Starting with default values.");
FindObjectOfType<MoneyManager>().currentMoney = 0;
}
theres more to the code but this is where im figuring the problem is at
I mean presumably it would be somewhere in the code that positions the player or the camera at the start of the scene
Maybe SaveManager.instance.LoadPlayerPosition(playerGameObject, data.playerPosition);?
there's very little context shared here for us to help
Hellou, I wonder if there's a way to vectorize two non aligned arrays in context of jobs and burst.
By non aligned i mean:
- Array A: 4 important values in each set without data in between
- Array B: 4 important values and one non important in between setd
The 4 important values of each array should match. So i could reinterpret the first array from float to float4. But the second I wouldn't be able to because the nonimportant value would fall between the rellevant floats4 and it would no longer match
Note that this is a simplified case. In the real scenario sizes of everything are unknown until scheduling the job and can vary a lot of size
My current solution for now is to not vectorize and do some indexing work
But if there's a know way to vectorize data that way i would get some boost
whats the debug log say for the "data.playerPosition.ToVector3()" on start?
it loads the same position as what was saved
which is at the right height?
yes, The childs of the tag player are not being loaded or saved correctly
thats something that would happen in the SaveManager script
thats more likely where the issue is
gotcha, Ill have more of a look after work
Im only saving position, Would i need to save rotation aswell?
id say if you want to you can, but for most games im sure its not that important
Hi im trying to make a rhythm game and setting the songposition value using dsptime, yet in unity the time of the song seems to be nearly a second ahead of what it shows in audactiy and i don't understand why. the audio clip has decompress on load, the audio settings are for best latency, play on awake is off and the clip is started in Start, and this isnt an audio offset issue, since im looking at the seconds here and unity is ahead of audacity. the first drop happens at 1.948 in audacity but around 2.5 in unity, by looking at the songpositiontext.
here's the code that handles the songposition
private void Awake()
{
musicSource = GetComponent<AudioSource>();
}
void Start()
{
songPosition = 0;
songPositionRounded = 0;
songPositionInBeats = 0;
songPositionCurrentBeat_int = 0;
songPositioninBar = 0;
dspSongTime = 0;
//Calculate the number of seconds between each beat
secPerBeat = 60f / songBpm;
//Record the time when the music starts
dspSongTime = (float)AudioSettings.dspTime;
//Start the music
musicSource.Play();
}
void FixedUpdate()
{
//determine how many seconds since the song started
songPosition = (float)(AudioSettings.dspTime - dspSongTime);
Debug.Log((float)dspSongTime);
Debug.Log((float)AudioSettings.dspTime);
//determine how many beats since the song started
songPositionInBeats = songPosition / secPerBeat;
songPositioninBar = songPositionInBeats / beatsPerBar;
if(songPositionInBeats > songPositionCurrentBeat_int + 1)
{
songPositionCurrentBeat_int++;
pc.changeFrame();
}
if (songPosition > songPositionRounded + 0)
{
songPositionRounded++;
//backgroud.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
}
songPositionText.text = songPosition.ToString();
}
}
```
is it possible to code something where you can colide with something from both sides
what does it mean to "colide with something from both sides"
yeah
i mean like you know how there are both sides in shader graphs and you can only colide on one side with a mesh
you can set up your physics queries to hit backfaces, i don't think rigidbodies detect collisions with backfaces though
oh dang
Hey, is anyone here who once tried git subtree or git worktree for reusing code? I am writing a bachelor thesis on the subject of code sharing and have not yet found anyone who has had any experience with it
I've used submodule for that purpose. We didn’t use subtree as it is not yet well supported with GUI, and we have designers and artists that are not used to git commands (or git at all). Generally speaking tho, in Unity it would be better to utilize UPM to reuse code.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Can someone help me understand why its not saving or loading my camera position correctly, but its loading and saving my player position correctly?
Start by debugging where you set data cameraposition, make sure that code is being executed
BinaryFormatter ☠️
oof, stay away from BinaryFormatter https://learn.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:45)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)
Saving game. Player position: (-53.62, 0.00, -37.70)
UnityEngine.Debug:Log (object)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:14)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)
Says its saving and load the camera position correctly, But my camera is not being loaded correctly its being loaded into the ground.
Damn didnt know that
Just switched to XmlSerializer
Im using the Starter asset, Its saving and loading the MainCamera position correctly, But the camera is still in the ground on loading
you're assigning the camera's position directly but using cinemachine. you need to change the vcam's position
is there a easier way to save the whole PlayerArmature GameObject with all the cameras etc, Instead of having the save the position of the PlayerArmature and then the Position of the Cameras etc?
Thank you very much! I didn't know about the missing GUI support. I also favor UPM, but I have to compare all usable methods I can find 🥲
@fresh spruce This is not related to a code channel. Move it to #💻┃unity-talk or #archived-networking really
Okay, thanks
@fresh spruce Moving means deleting original one. Don't cross-post
Play does not play immediately. You want to use PlayScheduled to schedule it to play in the future and give it enough time to prepare.
i managed to get it working by subtracting the musicSource.time from the dspsongtime in start, is this bad practice and can this cause issues though?
Yes, there's absolutely no consistency of Play's latency, so different devices, and even different plays of the same device in the same session, may have different offsets and mess up the player.
Here's someone else asking about rhythm game timing and I've given a more detailed answer in the thread: #1096003362199191582 message
Still having this issue
https://pastebin.com/6mZFZz0m
All the updated code,
Switched to XmlSerializer
The positions are all saving correctly
But the camera is loading in on the floor
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Saving game. Player position: (-48.74, 0.00, -40.21)
UnityEngine.Debug:Log (object)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:14)
Camera position saved: (-0.46, 1.40, -0.01)
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:42)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)
PlayerCameraRoot position saved: (0.00, 1.38, 0.00)
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:52)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)
PlayerFollowCamera position saved: (-0.46, 1.40, -0.02)
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:53)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)
Loaded player position: (-48.74, 0.00, -40.21)
UnityEngine.Debug:Log (object)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:40)
Loaded PlayerFollowCamera position: (-0.46, 1.40, -0.02)
UnityEngine.Debug:Log (object)
SaveManager:LoadGame () (at Assets/Scripts/Saving/SaveManager.cs:74)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:35)
Loaded PlayerCameraRoot position: (0.00, 1.38, 0.00)
UnityEngine.Debug:Log (object)
SaveManager:LoadGame () (at Assets/Scripts/Saving/SaveManager.cs:73)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:35)
Loaded camera position: (-0.46, 1.40, -0.01)
UnityEngine.Debug:Log (object)
SaveManager:LoadGame () (at Assets/Scripts/Saving/SaveManager.cs:72)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:35)
can you just step through it in the debugger and see if the value is correct at each stage? it should be fairly easy to see if the value and name are what you expect in the loaded save data
I really doubt the issue has anything to do with the saving/loading
it's probably just cinemachine not being configured properly
im using the starter asset controller, Its is configured properly
Saving and loading camera positions is useless if you're using cinemachine
the position of the camera is entirely dependent on your virtual camera settings
those are the things that would need to be saved/loaded
(assuming parts of it are changing)
Gotcha, I think i realize whats messing up
it works. 2 days to figure it out, finally works.
nvm
Figured out why its doing it tho, Idk how to fix it.
The PlayerFollowCamera sets it self on the ground
if i dont use the PlayerFollowCamera the save and load work fine, But then the mouse look doesnt work and you can only move the body and not use the mouse to look around. So i need to use it, But when using it it spawners on the floor
Does anyone have any advice on how to implement different controls for different game states (e.g. pause menu, world map, combat, dialogue)?
So far my solution has been to enable/disable game objects with MB components that handle interpreting player input on game state change (on pause, disable all other input listening components except pause menu). I was thinking maybe somehow implementing the disabling/enabling of input listening components as a FSM might be a good idea.
One way to solve this would be making use of the new input system. There you can have different action maps, which could respresent your game states, e.g. menu, combat and so on. In these actions maps are the different actions you could perform in these states. Those action maps can easily be enabled/disabled. How you handle this depends on your needs, there are some builtin components which might be good enough for your specific needs, or you have the possibility to implement your own inputmanager/reader whatever. There you could listen for your state changes and enable the respective maps.
What should I be looking for when trying to improve burst compiled code?
https://gyazo.com/c164d6739aa00b44329eb87ae658808c Hey all, I updated unity from 2021.3.19 to 2021.3.38 and now during initializion the scene reference for some scripts is wrong. In this script all the components on a gameobject are being initialized and managers are being found for the requested variables, however, for some scripts it gives a different scene reference (one that is not loaded) while they are all on the same gameobject and should have the same scene reference. Any idea what to do about this?
Probably a script execution order issue or something along those lines
That's just an invalid scene aka not a scene at all
Yea I thought it might be initializing to early and made a coroutine to wait untill the scene reference became valid but they actually never do for certain components
Wdym by "wait until the scene reference became valid"?
It's hard to help a lot here without seeing the code
I can't imagine any circumstance where this would be helpful
If gameObject.scene is not valid it's probably because you're running code on a prefab
well wanted to check if it was being called before Unity had a chance to fix the scene reference so tried to wait but it's never corrected to the right scene
yeah it is
oh I mean instances of a prefab
I think your code is actually running on a prefab
Not an instance of one
But I'm really taking a guess from very little information here
It's unclear where this scene variable comes from
hmm but I don't get how that's even possible, doesn't code on a prefab only run when it's instanciated
Please show some code
Code runs whenever you tell it to run
You can call a function on a prefab, no problem
well basically there's an autoInit that you can inject certain classes too
Ok so you're using some kind of DI framework
Yeah
Then it checks the dependencies it's looking for and tries to intialize it
but already in the AutoInit class where it all starts I have the invalid scene reference for some of the components on the prefab (or what I thought would be the instances)
and meanwhile other components run just fine with proper scene references
and well it worked as well on the previous version so not sure why it would run on the prefab now and not before
I don't really know how this DI framework works so it's hard to say
And it's unclear what code you're debugging above
Or what class it's in
so in the AutoInit class this Init function is run on Awake and then calls the fixdependencies which calls the injectdependencies
This Injectdependencies is what the gif is from and where the invalid scene causes a crash
Ok but where does the code run that depends on the dependencies having been injected?
The code that's causing you trouble in the first place
It's this code?
so this line basically because the scene is invalid when trying to look for the manager
Where's that line?
but I figured that's just a symptom of the issue and the cause is the invalid scene reference
That doesn't appear to be part of InjectDependencies
so basically that line with the actual exception is one more level down in the get function from the managers class
I mean...
I don't see how Awake is running on an object not in a scene
Can you just debug that?
btw I didn't write this code myself, so it's rough navigating it for me too
Like can you see Awake running where the gameObject.scene isn't valid?
And if so can you check which object that's happening for and what its instance id is?
It's currently happening for 3 different Objects in this scene, everything else still runs fine
Instance id for this object is : 58386
A positive instance ID indicates this object is a prefab. Instances of the prefab in the scene will have negative instance IDs
can you show the stack trace at the time where you're stopped at this breakpoint?
something weird is happening
okay this is interesting, it originates from the exact same function
I think you have a circular dependency probably
Looks like this object depends on some other objects which ulktimately depend on this one
so it brings you back to this instance which isn't fully created yet
yeah that makes sense
There also seems to be some UniRX observable thing going on in the middle there.
How can I initialize a subsection of a native array to a specific value?
I tried this
NativeArray<float> temp = new NativeArray<float>(height.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
UnsafeUtility.MemSet(temp.GetUnsafePtr(), Value, height.Length);
UnsafeUtility.MemCpyStride(settings.global_pr, height.Index*settings.pointsLength, temp.GetUnsafePtr(), 0, sizeof(float), height.Length);
temp.Dispose();
and it crashes unity
what type is Value?
float
MemSet accepts a byte
(byte)float also crashes
right because there's something off about this
MemSet's length parameter is probably expressed in bytes
but whne you do new NativeArray<float>(height.Length
also tried multiplying by sizeof(float) and still looking weird
that's in "number of floats"
Also wait which line crashes unity
UnsafeUtility.MemCpyStride(settings.global_pr, height.Index*settings.pointsLength, temp.GetUnsafePtr(), 0, sizeof(float), height.Length); this one, or the MemSet one?
i made a job to do that before
[BurstCompile(FloatPrecision.Standard, FloatMode.Fast, CompileSynchronously = true)]
internal struct ConstantJob : IJobFor
{
float Value;
[NativeDisableContainerSafetyRestriction] [WriteOnly]
NativeArray<float4> globalMap;
IndexAndResolution target;
int verticesLength;
public void Execute(int i)
{
globalMap[i + target.Index*verticesLength] = Value;
}
public static JobHandle ScheduleParallel(NativeArray<float4> globalMap,
float Value, IndexAndResolution target,
int arrayLength, JobHandle dependency) => new ConstantJob()
{
globalMap = globalMap,
target = target,
verticesLength = arrayLength/4,
Value = Value,
}.ScheduleParallel(target.Length/4, target.Resolution, dependency);
}
but I felt it was too much to just initalize a part of an array
well, now i cant get it to crash
You put 0 in for sourceStride?
nvm crashed
for some reason this line triggers the awake of the autoInit script again although I don't get why as it's just setting the parent for the original instance
yup
what is e?
and what is container?
those could be properties
which could be doing anything
yup this one crashed
Looks like maybe one of them is probably UnityRxObservable or something?
yeah I don't think your params are correct for that
Received signal SIGSEGV
Obtained 62 stack frames
0x00007ff6350ff98e (Unity) UnsafeUtility_CUSTOM_MemCpyStride
0x00000241828ce345 (Mono JIT Code) (wrapper managed-to-native) Unity.Collections.LowLevel.Unsafe.UnsafeUtility:MemCpyStride (void*,int,void*,int,int,int)
0x00000241828cde0b (Mono JIT Code) sapra.InfiniteLands.Nodes.ConstantNode:ProcessData (sapra.InfiniteLands.GenerationSettings) (at
it's a chunk container that's holding the asteroids in this case (not sure how the chunk code works yet, haven't seen that part of this codebase yet)
but I checked and all the objects with this issue are chunk objects so this is proably the cause of it
Already big thanks in advance @sly grove , you've been a big help to get me on the right track
Anyone ever used UGS: "Cloud Save" - I want to store a player JSON file somewhere easy/convenient - but cloud save looks like KVP based storage.. Part of me says it's ok to stuff a json blob in a KVP but I'm not sure what kind of side effects that'll have - escaping characters and all that
I could also serialize it as a byte[] to make user tampering a little more inconvenient but I'm not too worried about that - it'd require some deseralization tools above and beyond a text editor for support to edit in some prizes for pissed off customers. 😛
(Also I'm interested in any performance feedback - especially if I'm doing something like await CloudSaveService....LoadAllAsync() before letting a user play
Not me exactly, but I vaguely understand what you’re saying. I’ve learned a bunch getting a gameCI container working for me.
Wait omg the il2cpp question disappear… no!
I was just about to answer it!
Yea? It was an interesting Q. What was your response going to be?
There's an undocumented attribute used by Unity to mark a class to use eager initialization. It's not public, but you can define it yourself, it just needs to be in the right namespace with the right name:
namespace Unity.IL2CPP.CompilerServices
{
/// <summary>
/// This is used to indicate to IL2CPP that the static constructors should be executed eagerly at startup
/// rather than lazily at runtime.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
internal class Il2CppEagerStaticClassConstructionAttribute : Attribute
{
}
}
I was just going to say “I don’t know but I do know Unity builder uses binaries packaged with Unity editor; I’d read the build log and see what commands are being run and maybe try to run the commands outside of Unity builder”
I can't remember the name of the user who asked the question 😔
Can you elaborate on this? For my own education— feel free to over explain
Same… same… I was hoping they asked the Q somewhere else but nothing came up in recent search history.
By default, IL2CPP will match the behavior of C#, where if you have a static field in a class initialized to some value, like:
public class MyScript : MonoBehaviour
{
private static int randomNumber = Random.Range(0, 100);
}
the Random.Range will not be called until MyScript is used for the first time in some capacity. Instantiated, or a static method called on it. IL2CPP does this by adding a check in every "entry point" of the type to check if it's been initialized yet, and initialize it if not.
That's cool, but now that means it will always perform that check, even after it's initialized. This attribute avoids that by telling the IL2CPP transpiler to initialize this class at startup instead, meaning the Random.Range will get called right away.
With lots of types and lots of static fields, this could significantly increase loading time if it was enabled by default.
And it wouldn't match the behavior in C# Mono, which doesn't have any eager static initialization, leading to potential bugs that only happen in IL2CPP builds.
So I can enable/disable behaviors (like eager static initialization) by declaring a C# class with the right name and the right method, eh? If I wanted another behavior, is there any documentation on this topic available? Or is it a matter of reading through source code & inferring this?
I just vaguely remembered seeing this while browsing the UnityCsReference repo for some other reasons. And this idea of just needing to match the namespace and name of an attribute which is meant as a hint to a compiler is common in C#. It would be more work to verify the attribute is the "real" one, easier to just compare the name, so that's what most compilers do.
There is also a documented attribute for other IL2CPP optimizations, [Il2CppSetOptions]. But it's the same way, where it's not actually defined anywhere, Unity tells you to copy it from a .cs file in the Unity editor install folder, but as long as the type name and namespace matches, you can just write it yourself in any file.
Now, I haven't used Il2CppEagerStaticClassConstruction myself, and can't find any threads about others using it, so maybe it doesn't work or has some caveats. But it's used in Unity.Mathematics, which is just a package with source code which is compiled with the rest of your code, so I think it should work, unless Unity has specific assemblies whitelisted, which would be weird.
Cool, thanks for sharing all this. Hopefully the original asker comes back and sees some of this conversation.
Does anyone have any updates on this issue? Is AsyncGPUReadback.RequestIntoNativeSlice() working for anyone? I have some data that's managed by a large native array and I need to use NativeSlices to copy data to it--I would really like to not have to copy it to a temp native array.
How to reproduce: 1. Download and open the attached project 2. Enter Play mode 3. Observe the console window Expected outcome: No er...
And do you have multiple requests active reading into different parts of the same array, like Unity's comment suggests?
yeah--I was hoping they'd eventually change it so the safety checks occur on the native slice
I'm not sure if this would work, but what about creating a new NativeArray that's pointing to a slice of the already allocated NativeArray?
You can use this method to create a NativeArray from an existing pointer:
https://docs.unity3d.com/ScriptReference/Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray.html
And use this method to get the pointer from a NativeArray:
https://docs.unity3d.com/ScriptReference/Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.GetUnsafePtr.html
hmm... I don't like writing unsafe code but I'll give it a try & tell u if it works
To offset the pointer, you'll need to cast the void* to T*, whatever the element type of your array is, and then you should be able to just do pointer += startIndex
You might also be able to replace or reconfigure the AtomicSafetyHandle of your NativeSlice and avoid all this unsafe stuff, but I haven't messed around with that before.
https://docs.unity3d.com/ScriptReference/Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.GetAtomicSafetyHandle.html
I may be interpreting the documentation wrong, but it appears Unity does not think ConvertExistingDataToNativeArray actually gives an instance of a native array. There may be some safety parameters I need to fiddle with. I'll try the original way by changing the saftey handle as you said
The allocator should be set to Allocator.None in this case.
Otherwise, the ownership of the memory is moved.
Oh that makes sense tysm
I got it to work! You can indeed get a slice of a native array like this, I just needed to fidget with the saftey handle.
https://forum.unity.com/threads/convertexistingdatatonativearray-and-atomicsafetyhandle.878575/
Just added one more line to make it work.
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref nativeSlice, AtomicSafetyHandle.GetTempMemoryHandle());
Does anyone know how the rag-doll wizard actually calculates the mass ratios ?
Currently trying to implement a URP tessellation shader and I'm getting some really weird errors
It's saying there's an unterminated conditional expression on line 606:
clip(alpha - surfaceDescription.AlphaClipThreshold);```
Weirdly though the error doesn't go away even after I comment out the code
```c
// #if _ALPHATEST_ON
// half alpha = surfaceDescription.Alpha;
// clip(alpha - surfaceDescription.AlphaClipThreshold);
// #elif _SURFACE_TYPE_TRANSPARENT
// half alpha = surfaceDescription.Alpha;
// #else
// half alpha = 1;
// #endif```
Why it also says I have no vert/frag I have no idea
If I completely delete all the frag code except:
```c
half4 frag(DomainOutput tess) : SV_TARGET
{
return half4(1, 0, 0, 1);
}```
It now decides the error is on this line:
```c
#ifdef _NORMALMAP
float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz);
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
#if _NORMAL_DROPOFF_TS
inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld);
#elif _NORMAL_DROPOFF_OS
inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
#elif _NORMAL_DROPOFF_WS
inputData.normalWS = surfaceDescription.NormalWS; // Error!!!
#endif
#else
inputData.normalWS = input.normalWS;
#endif```
Anyone know what's going on here?
Ah nvm got it. Should have just gone with the most obvious and simple answer. I was missing an #endif
Hey yall, I need help with steam workshop implementation for custom maps ONLY.
At the moment in my game I have a script that picks a random prefab from a list of prefabs to generate as a map every few in-game rounds.
So the way it works in simple terms is I have a list of prefabs for maps and it picks one semi-randomly to generate
The prefabs are just FBX geometry with read/write permissions and some empty transforms with tags. Each of the FBX objects (from the geometry) have a tag and layer too
What I'm trying to figure out, is how do I make these prefabs exportable (idk into what kind of file format), and then loadable from a folder in the built-application folder.
Should be simple enough in concept but I have no idea where to start as obviously building an application encodes everything
there's nothing built into unity for this really, pick a serialization format/library and write the mesh and transform data out to a file
dont cross post
sorry
Is there an AI tool where you can upload your codebase, that will detect logic errors in the code?
The simplest example would be something like:
Debug.Log(i.ToString());
}```
And then I could ask it, why does my code only print 1-4 and not 5?
But then for complex issues in large codebases
ChatGPT can do this a little, but not really and not across multiple files (maybe the paid version can?)
I hate to tell you this, that code will not print anything
there I fixed it, I'm sure that's very helpful to my actual question
to answer your question, I think MS CoPilot can do that
you would definitely have to use an AI which actually understands code which GPT etc do not
MS CoPilot seems worse than Chat GPT
this is the limitation of LLM's, just because they produce something that looks like code people think it is writing code. It is not, it is writing text that just happens to compile (sometimes)
From my experience, AI is not yet able to point out complex logical issues consistently.
well they do a pretty good job at most basic tasks and even help a lot with more complex tasks
I know for example there's AI where you can just upload a book and it will summarize it for you, even generate prompts if you need to study it
but a book is not code
Doesn't seem too far fetched to be able to do the same with "understanding" code
code is just another language not?
no
you really need to know how LLM's work. They don't write, they put together words in what is, according to their training set, a statistically likely combination, they have no understanding whatsoever what any of it actually means
I've seen a video of a robot using ~~ GPT 4~~ OpenAI that completes "complex" tasks in the real world, pretty sure it understands
Well I designed and developed ML driven NPC's for games and I can guarantee you the only thing they 'know' is what I tell them
but yeah I do not understand how LLM's work
neither do I really care
I'm sure someone will come up with an AI that can detect logic errors in complex code soon enough
maybe I'll try the paid version of MS CoPilot for a month
there actually are some tools to examine the "logic error" in your code but not using ai, by defining the logic and state and check if your program works (ie not volatile the rules) under some states of your program iirc
what tools?
In the context of hardware and software systems, formal verification is the act of proving or disproving the correctness of a system with respect to a certain formal specification or property, using formal methods of mathematics.
Formal verification is a key incentive for formal specification of systems, and is at the core of formal methods.
It...
Any tips for using multiple threads in unity?
Target platform: Windows and Mac
Context: Working on my thesis integrating some AI technologies into a game context. Since i am trying to reduce time to first byte latency i am making multiple calls to my speech synthesis service, and while it is stable now, i would like to move the synthesis to work independently from the main thread, as how i see it, the only place i really need to think about the main thread when it comes to speech synthesis, would be when i add the audio to the audio buffer.
So i guess what i am wondering is whether i can use C# Thread or similar and still expect the project to compile into a working a working executable for mac or windows.
(Not that i cant just test my thesis without compiling it, just think it would be good for my writeup to be able to say that it also works when compiled)
Since i might have many external web api calls etc, using coroutines and with stuff like waituntil, quickly becomes messy when trying to avoid bad timings.
You can use everything in System.Threading and it will work on all platforms Unity supports except for Web.
@sage radish Ah that’s good news, appreciate the help ^^
For audio, there are ways to hook into Unity's audio thread and feed data directly. Such as OnAudioFilterRead and AudioClip.Create with a PCMReaderCallback.
@sage radish Yes that’s what i am doing 🙂 first i used OnAudioFilterRead, but i changed to PCMReaderCallback as i found it to be more fitting for my project. But good to know that i found the two options you mentioned, means i am going in the right direction.
PCMReaderCallback has some additional latency, if that matters to you.
@sage radish oh it does, Do you know by how much ?, i mean i could go back to the OnAudioFilterRead solution, just need to implement the workaround for another library. Basically i use a library called uLipSync, which uses OnAudioFilterRead, so i had to Call a function in the library to make sure it worked as normal
I don't remember if I wrote it down somewhere, let me see if I can something.
I don't think I did, but in my memory it was at least 500ms+
Ill have to look into that
Pcm gave 390ms so close
Though didnt Get stutter with it like i did with OnAudioFilterRead, though i guess ill take one last look at this issue before making a choice
PCMReaderCallback avoids stutters because it has such a large buffer, which also adds latency.
right, that makes sense. Guess ill have to fix something with the buffer then. I mean, with OnAudioFilterRead i think it was something like 5ms from first byte chunk received from the synthesiser to it being read in OnAudioFilterRead, and the stutter is really only in the beginning, and maybe now and then if i dont remember wrong.
You may want to wait until you have some minimum number of samples downloaded before starting to play it back. Of course, adds some latency, but maybe 15-30ms.
actually that might be a good idea. i guess i could calculate the expected byte size given my audio format for the specificed amount of time in ms, and when i receive audio ill wait until i have received that amount of bytes ?
in my case i guess that would be 2646.0 bytes for 30ms. (high quality audio, so could probably reduce latency by choosing worse audio quality if necessary.
nvm i that didnt make sense haha
(Also need to take into account network speed, you are making the assumption that your download speed is always faster than playback speed, or at least fast enough to play until the end without pauses)
@scenic forge ah yeah ill have to look into that as well.
I'm not sure how much that matters in the context of your original question though, "needing to take into account slow downloading speed" and "buffering until there's enough data to play the rest without interruption" are problems and solutions not unique to AI speech synthesis, but anything that needs to be transmitted across slow network in general.
You can perhaps leave "to improve experience in slow network consider similar approaches to video buffering" as a remark and focus more on things that are specific to AI speech synthesis, such as streaming the output while synthesizing like how LLMs stream their responses.
@scenic forge i mean i think you are right, though since i am inherently just making a demo for my thesis i am allowed to have limiations. So if i cant find a solution to this within the next few days, then ill probably just use the least stuttery version i have. At the moment i read my LLMs incoming stream and wait until i have N number of sentences, then i send that to be synthesised. just to kind of work around the latency.
you can only print through the system print dialog
no im sure its possible to print by code
ofc you can print via code, but the libraries for doing that easily are not part of the unity runtime
on windows (non-portable): https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing?view=net-8.0
I'm attempting to create a sort of Field of View cone effect. It's working for the most part, except it only works correctly if the look at point and the player are on the same y coord. If you are above or below that value it starts to get skewed but not exponentially so and only by a few degrees.
Here is the code I'm trying to use to calculate things: private void ```LateUpdate()
{
if(UseGetFoV)
fov = GetOriginVertexAngle();
if(UseSetAim)
SetAimDirection(PortalObject.transform.position - origin);
angle = startingAngle;
verts = new Vector3[rayCount + 1 + 1];
uv = new Vector2[verts.Length];
triangles = new int[rayCount * 3];
verts[0] = origin;
currentOriginPoint = origin;
int vertIndex = 1;
int triIndex = 0;
// Set layer mask to exclude character colliders;
for (int i = 0; i <= rayCount; i++)
{
Vector3 vertex;
RaycastHit2D rayHit = Physics2D.Raycast(origin, GetVectorFromAngle(angle), viewDistance, layerMask);
if (rayHit.collider == null)
{
vertex = origin + GetVectorFromAngle(angle) * viewDistance;
}
else
{
vertex = rayHit.point;
}
verts[vertIndex] = vertex;
if (i > 0)
{
triangles[triIndex + 0] = 0;
triangles[triIndex + 1] = vertIndex - 1;
triangles[triIndex + 2] = vertIndex;
triIndex += 3;
}
vertIndex++;
angle -= angleIncrease;
}
fovMesh.vertices = verts;
fovMesh.uv = uv;
fovMesh.triangles = triangles;
fovMesh.RecalculateBounds();
}
private Vector3 GetVectorFromAngle(float angle)
{
float angleRad = angle * (Mathf.PI / 180f);
return new Vector3(Mathf.Cos(angleRad), Mathf.Sin(angleRad));
}```
Mostly using code from CodeMonkey's FoV tutorial, but can't figure out why the angle isn't lining up as expected.
In the left image the player char y = 0.355 in the right the player y = 1.071. If it works correctly the FoV should expand to fit the space between the green points on the right, and set the center of the FoV as the point between those points.
I find it suspicious you're using world space coordinates for mesh construction. Are you sure it's skewed and not simply rotated? Atm the mesh will only be correct if it's rendered by a mesh renderer at the origin with identity scale and rotation
Sorry let me rephrase, the mesh is correct. The aim point is off from center. So I can turn off the SetAim and manually change the starting angle so it fits perfectly between the two points. It is only off when the y of the character transform is above or below the y value of the target point.
I'm thinking it has something to do with the Atan2 used to get the angle from vector. ```public void SetAimDirection(Vector3 dirToPortal)//Vector3 dir)
{
float angleToStart = GetAngleFromVectorFloat(dirToPortal);
startingAngle = angleToStart + (fov / 2f);
}
private float GetAngleFromVectorFloat(Vector3 dir)
{
dir = dir.normalized;
float n = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
if (n < 0) n += 360;
return n;
}
private float GetOriginVertexAngle()
{
Vector3 innerNPos = InnerN.transform.position;
Vector3 innerSPos = InnerS.transform.position;
float n = Vector3.SignedAngle(innerNPos - origin, innerSPos - origin, Vector3.up);
if (n < 0) n += 360;
return n;
}```
What happens if you translate the player a few units in the +x direction?
I when x is changed the fov will increase or decrease to fit between the green points. As far as I can tell this is calculating correctly regardless of position.
float n = Vector3.SignedAngle(innerNPos - origin, innerSPos - origin, Vector3.up);```
is it really correct to use the y axis as the rotation axis here? Isn't the world on the XY plane?
That would imply you should use Vector3.forward or Vector3.back as the axis
I had it on forward originally. I've changed it a few times when debugging the aim issue.
seems worth a Debug.Log or two to verify it's working properly
I think what I need to do is use SignedAngle to get the angle between the portalCenter dir and vector3(1,0,0).
Got it most of the way now. What I needed was the angle from the x axis down to the top of the mesh to find the starting angle. This is what I used to find the correct angle. private float GetStartingAngle(Vector3 centerDir) { centerDir = centerDir.normalized; float n = Vector3.SignedAngle(Vector3.right,InnerN.transform.position - origin , Vector3.forward); if (n < 0) n += 360; return n; } It doesn't work on the right side of the portal, but that may be due to using vector3.forward I suspect. So need do that better and it should be fulling working.
Man that was haunting me.
i wanna open an application by javascript in unity... is there anybody to help me ? 😦
i just want to launch an application from path when my webgl export is starting
i've searched a lot but i've didn't find correct code for javascript
Is there any way to have unity test runner output failed assertions to console?
or make it so that you can click a stack trace?
(editor test specifically)
do not cross post
is it an advanced q or no?
based on the level of questions in general, yes I would say it's advanced
also, if anyone uses rider - is there any way to make rider auto break on an exception thrown in test runner?
Yes, go to the breakpoint settings and enable any exception in the exceptions list
Im guessing you can't do this because it might be running tests in parallel and thus not know where errors come from and/or get spammed
you mean these? doesn't work - should not these are editor tests not playmode
ty good sir
I have encountered a really weird problem with one of my functions, it seems that if the function is provided a negative number, it always returns 0. This is odd because its a simple function thats supposed to still be able to produce results for negative values. It got even stranger when I tried doing Mathf.Abs() inside the function on the input value, and it would still return 0. Its only if I do Mathf.Abs on the value before I make the function call that it produces a nonzero result. Is there anything I can do to fix this?
public float Evaluate(float slip)
{
return _peak * Mathf.Sin(_shape * Mathf.Atan(_stiffness * slip - _curvature * (_stiffness * slip - Mathf.Atan(_stiffness * slip))));
}
with what parameters?
I slapped in -0.5 (slip), 1f, 1f, 1f, 1f for those values in order and out comes a negative number just fine
in engine?
for me those parameters still produce zero on negative. Im wondering if its some weird memory issue because Im creating a lot of variables in the function
float
slipRatio = radialSpeed / localVelocity.z - 1,
slipAngle = -Mathf.Atan2(localVelocity.x, Mathf.Abs(radialSpeed)) * Mathf.Rad2Deg;
float
frictionClampX = normalForce * sidewaysFrictionCurve.Evaluate(Mathf.Abs(slipAngle)),
frictionClampZ = normalForce * forwardFrictionCurve.Evaluate(Mathf.Abs(slipRatio));
this is the context of the usage, as you can see im currently placing abs on the function input because of the issue
are you doing weird things that might mangle memory? That's a weird take
oh my god im lobotomized
I had an animation curve named a variable that im now using for something else
damn, yep Im just dumb. Cant believe I spent an hour on that.
Thanks tho
I have a cube that can move left,right,forwards and backwards and i want it to move up and down when it hits a object. I've gotten it to do that but it functions really weirdly and does not deal with corners except in very rare occasions. It also somtimes makes it so when i go forward i actually go backwards and then i have to press the inverted keys for it. and instead of the object going up a wall when i try walk onto them it will actually try walk down it unless i press down which actually goes upwards.
I was hoping someone could have a look at my code and see what the issues might be.
Code: https://gdl.space/azazoqafir.cs (I Apologise for the Super messy Code)
I cannot seem to successfully connect either Visual Studio or Rider to the AssetImportWorker Unity instances. Is there a command-line option needed to turn on debug mode so I can debug importer code running there?
For a multiplayer game like Helldivers, is there anything to be aware of if I wanted to implement bug behavior as a server authoritative behavior tree?
I don’t think I need to clone the behavior tree onto any of the game clients as it’ll be running in server memory. The only messages sent over network should be the action outcome (aka method calls with args to game components) e.g. move towards player, attack player X. Right?
It seems like a hassle to reconcile behavior trees if they ran on both client and server. Is there a reason I’d want one game agent’s behavior tree running on the game server AND n game clients?
I don't know anything about helldivers but one reason to duplicate simulation logic on the clients in general is to implement client-side prediction. This is done frequently for physics for example, to improve the perceived responsiveness of the game
It’s kind of like left for dead, if you’re familiar.
Yea I’m trying to think if an AI would benefit from client side prediction. One scenario is if a bug gets killed by a player, a player may like to see their kill immediately. But waiting 50-100ms round trip might not be that big of a deal to avoid reconciliation logic?
Seems different than physics for some reason.
Let's say you walk around a corner and a zombie notices you and starts attacking. It would be weird if you need a network round trip before the zombie reacts to you
(using the l4d example)
But of course when you do prediction you also need to do reconciliation logic and that gets very complicated very quickly
Appreciate being able to discuss. I’m just thinking.
You might be right that players will notice the round trip. I just don’t know.
If they do and it feels wrong/off, then it seems worth it to have the tree also running on the game clients.
I’ll have to AB test it with something basic to see if some play testers notice.
I will say this: another benefit would be players on slower connections would probably have a better experience, right?
It’s just… reconciling is quite the art isn’t it? E.g. a fallback node using randomness to choose a child node would be inconsistent across all the tree sims for one game agent. I winder if there’s a way of getting deterministic randomness across the sims; can I seed a random with the same seed?
Multiplayer is definitely tricky..
other players and AI are typically never predicted by the local player unless it's very physics heavy. eg: in rocket league the local player is predicting other players and the ball since the premise of the game involves smashing networked physics entities into each other. this isn't perfect at all, and if you do your googling, you'll see a lot of pissed off people complaining about going through the ball, other players teleporting after collisions etc.
if the AI movement gets mispredicted on the client and your player shoots him in the head, the kill will fail and you'll get an ugly correction and an angry player
where as properly implemented lag compensation and entity interpolation, a headshot will always be a headshot unless you're enduring heavy packet loss (or if you die on the server before your packets reach the server). the movement of said entity will also be smooth as butter since the states are held in an interpolation buffer to account for bad network conditions. both have their pros and cons but typically you're not gonna want to predict that. especially in a fast paced shooter.
to answer your question nobody is going to notice a <100ms response. upwards of 200-300+ will be noticeable though. most (if not all) modern AAA online shooters use entity interpolation and lag compensation.
hey there how can i modify meshes in an ecs system
To leverage full power of parallel jobs and burst you can get native buffer pointers via Mesh.GetNativeVertexBufferPtr/Mesh.GetNativeIndexBufferPtr and pass them into jobs to work with.
Users can work around this issue by declaring the System.Runtime.CompilerServices.IsExternalInit type in their own projects.
Does this actually work in all cases or are there some edgecases which break?
https://docs.unity3d.com/2021.3/Documentation/Manual/CSharpCompiler.html
For init only setter? Works for me and I haven't seen anything wrong with it.
Keep in mind this is just a compiler attribute, it has zero effect on runtime code.
Compiler simply looks for its existence and then prevent you from reassigning after init by emitting a compiler error.
Interesting
It's a bit weird that Unity wouldn't just include it if it works in all cases
I'm guessing they rather focusing on effort migrating to Core rather than patching random things up, although it would be really nice since this is like literally a few lines of code for gaining access to init only setters and records which are two very nice C# features.
On that note, a lot of features being simply compiler checks/down leveling is one of the things I really like about C#. It's why things like PolySharp is possible.
Yeah it's cool, just kind of sus imo
I want to instantiate a prefab that connects to an already existing one. At the top of the hierarchy, I have a simple object with a BoxCollider the size of the prefab itself. Is there a way I can get a reference to the topmost object - and that object only - without iterating through its children?
For context I'm trying to instantiate rooms that connect to one another, like a dungeon crawler. For each room added, I want to check if the BoxCollider of the next room will intersect with any existing rooms
when you say get a reference to the topmost object, what do you mean? in what context?
where would you have to iterate through the children?
I'm trying to get a reference to the topmost parent of the hierarchy while excluding all other objects. Just wondering if there's a way to do this without iterating through all of the object's children and removing them
Essentially I want to instantiate just the topmost parent and nothing else
you mean the topmost object of the prefab being instantiated, or the object that will become its parent?
Just the topmost object of the prefab being instantiated :3
how are you instantiating it if you don't already have a reference to that 🤔
I do have a reference to the prefab itself, but am wondering how I can just instantiate the top most object and nothing else
why would you have the other objects in the prefab if you're not instantating them?
when you get the bounds of a collider through collider.bounds.size on an uninstantiated object, it returns (0,0,0) - so my thought was to just instantiate the topmost object, grab and check the collider bounds, then instantiate the full prefab if it doesn't intersect with anything
Was also thinking of just using collider.size but I'd still have to create a collider to test if it intersects anyway
that's in world space and it's not in the world so that makes sense, but you could just do a box cast using the center and size properties?
box overlap not box cast i guess
I think this is the crux of why reconciliation is an art. Given an inconsistency like what you say, it’s up to the developer to decide what happens.
E.g. in an online shooter given player X headshots player Y on X simulation, but player Y had actually run behind a corner on Y simulation, the game devs can say “we favor the shooter’s simulation” and resolve that the headshot happened. Also how in many games two people can headshot each other.
That’s also why I’d rather not have to decide what behaviors have to be reconciled and let the server be the authority.
Can I create these type of shadows using light2d in urp?
I want runtime shadows, clearly they should change at runtime, I mean the direction and length
Light2d generally can generate shadows like below
Someone here knows how to make the login session not to stay inside the files of the game when I make a version so my account is not there for another user?
you're going to need to provide a lot more detail than that
not possible, you need to go via a server or prompt the user to enter their own credentials
wdym?
I presume you are talking about your user id/password to a service are you not
@upbeat path i send you dm so we dont flood the channel
no
@serene oxide Will you please stop DMing me before I report you to the moderators
wtf why? im just asking you how to solve it lol @upbeat path
<@&502884371011731486>
!warn 186085307094007808 Don't send unsolicited DMs read #📖┃code-of-conduct
diegogb has been warned.
This may be asking for much but does anyone know anyway to allow for CPU-side threaded/asynchronous modification of multiple sections in a compute/graphics buffer? For instance, ComputeBuffer.BeginWrite() allows for one-time CPU-side writing to one section of a GPU buffer followed by an .EndWrite(), but you can't beginWrite before ending the previous write operation.
I am able to allocate the sections to copy synchronously on the main thread(so I can guarantee each section is separate) but want to be able to actually copy the contents in several async threads. I'm willing to write my own unsafe buffer access logic to do so, is something like this possible?
With BeginWrite you will get NativeArray. Make a Job with IJobFor interface (https://docs.unity3d.com/ScriptReference/Unity.Jobs.IJobFor.html). Pass obtained NativeArray to it. Write a copy logic. Schedule job and call Complete for returned JobHandle. Do EndWrite.
That's not exactly what I mean. When you call EndWrite you have to specify the number of things you changed, which is calculated linearly from the offset you begin write from. However, I am editing multiple non-continuous regions of an extremely large compute buffer. What I'm searching for is starting multiple write operations simultaneously and then being able to end each one with an instance of the write task or smthing.
You have two options here:
- Work with whole buffer memory. "The returned native array points directly to GPU memory if possible" documentation says. Update necessary portions in a preferable way. For
EndWritecall specify full buffer count. As long as you work directly with GPU memory there is no overhead (and copying) at all atEndWrite. - Make own "shadow" memory copy for compute buffer data. Work with it by recoring changed portions. When data is ready, make several ComputeBuffer.SetData calls with proper size and offsets to update only changed parts.
Thanks, I'm currently doing the second option. I have some async tasks that reads from disk to GPU memory and I was hoping I could do it without copying to cpu managed ram. Hopefully we'll get the option to do this someday.
I don't see how that would be possible. I don't think the GPU has access to disk drives or the ability to interpret the data correctly from them. There would probably need to be considerable changes both to the GPU and the computer architecture in general for something like that to work.
Or so I was gonna say, but then I googled and found about DirectStorage technology in DX12, that apparently streamlines the loading process from disk into the GPU, only using RAM temporarily. It does require compatible hardware though, so what I said above is not wrong.
Of course I do mean that it tries to go from disk to GPU but has to go through cpu memory. C#'s most common way of dealing with files, filestream is a section of cpu memory. I'm just trying to reduce how many times I need to copy it to memory before I can get to the intended destination in GPU memory.
That's interesting, wish we can get a more accepted standard for this kind of stuff
is there anyway to create a button in world in scene for editor ?
Something like Handles.Button?
https://docs.unity3d.com/ScriptReference/Handles.Button.html
thanks so much
It's in the editor namespace so make sure you account for that
How do people handle secret values that works for local and production? I tried envvars but can’t find a good development story (more later).
For some reason when I’m running my game in the Unity editor I can’t write envvars via my developer tool, which seems insane to me. If I read the envvar right after I write it, it’s undefined for some absolutely mysterious reason. The production Linux server build has no issues reading passed in envvars.
Using envvars in this way would allow me not to make development into a special case. That said, any advice on how to pass on secrets that work for local and prod?
Ideally I don’t want these secret values in any serializable fields because the repo is public, and I don’t want to accidentally publish the secrets on a git push.
Has this question not already been answered?
You mean you're setting it with Environment.SetEnvironmentVariable and reading it with Environment. GetEnvironmentVariable?
Exactly
Can you remind me what the answer is?
I ideally want to not make local a special case. Can you see why using player/editor prefs would mean my game software code would have to handle local and prod differently?
The cool thing about my envvar trick (if it worked) is that my game software code would’ve only had to know “I pull in secrets via envvar” and that would’ve worked in the unity editor and production. That’s the kind of solution I’m hoping for, if that makes any sense?
I use a dependency injection pattern to solve this. If some class needs a secret to function, have it part of the constructor. How the secret is produced can be different for local and prod, but it only needs to be different in one place.
Or just make a static method somewhere for reading environment variables which wraps around Environment.GetEnvironmentVariable, except it has a #if UNITY_EDITOR which reads it from somewhere else instead.
But the dependency injection method is preferred for making your classes easily testable by themselves, without needing to modify the environment to suit them.
Ignoring the DI & testable comments (preaching to the choir :), you do bring up a good point that wrapping reading the secret value in the UNITY_EDITOR directive like that is probably the best way to minimize deviation in game software code. Cool, moving forward.
I'm currently trying to use the Microsoft.Speech.Recognition namespace, but it seems like Unity's version of mscorlib.dll is outdated and doesn't have a method called from the namespace, so I can't use it. Does anyone know if it's possible to update mscorlib.dll and if so, how?
you cannot update core lib. what .Net version is the dll you are trying to use?
It's .Net Framework v3.5
too old, you need .Net 4.5 or above up to 4.7.2
What's the most proper way to make a multiplayer physics/navmeshing?
Max players amount is 4, but world itself is large, and mostly unloaded(due to chunking system)
In minecraft it's all done by server, but game has blocks instead of meshes, and custom navigation on top, and unity provides own navmesh and own physics
and well, meshes have thousands of verticies, so i probably need some API or just use what unity provides like NetCode for GameObjects/Entities
But that means that host player is also a server, and all collisions and AI stuff would be calculated on his machine
If you're talking about the built-in navmesh, it is not very compatible with chunk loading because it is calculated per-chunk and cannot connect between chunks(that's unless they've updated the system). You're probably better off building your own nav-algorithm.
Just guessing, but having all physics calculations being done on client side is probably easier and a good starting point, but may be more vulnerable to client-side hacking. Eventually you would want everything to be done on the host player unless you trust your userbase to not cheat.
I mean it's just a coop 4players openworld game
one player starts server, 3 guys connect and then all 4 get tossed to the actual game
so i don't think there would be cheating
but still, the synchronization is what should be prioritized ig
I prefer server authoritative; I also prefer server client model over peer to peer. Sounds like you do too?
If your game is largely physics based, run physics on all 5 simulations (4 players + game server) but allow server to correct the game clients if they mispredict.
A game server only needs to “render” the nav mesh that’s around players; to save resources, you can disable nav meshes that aren’t relevant to a particular piece of the level.
Well, my game is mostly static, but there are NPC which walk around, and also all pickable objects can be pushed around with players' bodies(like some random axe which can be pushed from chopping block, moved to the edge of the mounatin and then launched with a spell explosion)
and well, npc's might turn to lootable ragdolls on death
and yeah, i just transfer packets over UDP/TCP between players and server
so well, i think that packets should mostly update physical objects' positions, and player coords/states/animations
and sometimes damage/death/ragdoll-turn/item pick-up
idk if this system will be compatible with combat tho
mmorpgs are doing combat quite well
but idk how they achieve it
is this really an unnecessary assignment?
yes because you don't use that variable after assigning it
also not an advanced question
To be clear, + in a delegate returns a new instance, so despite it being a reference type it's not modifying it
#archived-code-general message Maybe someone has a clue here for this (disambugation for IEnumerator between mscorlib and netstandard)
in DOTS what is the best way to hook a BufferLookup into the job dependency system? i have a job in system A that modifies a bunch of elements in a buffer. a second job in system B needs to do an entity lookup and uses these values. both systems need rw access. what am i missing?
as it is, i get errors that both are trying to access the same buffer before calling Complete(). there should be a way to do with better than calling Complete() right?
i think i understand. if i am understanding correctly, one system isn't using a job, its running on main thread which would bypass the dependency system
Should ask in #1062393052863414313 next time
I am putting a hexagon onto a mesh that is itself also a grid of hexagons. and I get these serrated edges (left) whenever it transitions to a new row, while other edges are clean (right). I'm sure there is an analogue to this when drawing polygons in regular square grids, but I'm not sure what the fix would be.
Here is my code for checking whether a cell is within the hexagon:
private bool PointInHexagon(float x, float z)
{
int w = widthCells;
int h = heightCells;
// Convert x and z to be between 0 and 1
x = x / (w - 1);
z = z / (h - 1);
// Translate point to be relative to the center of the hexagon and normalize
x = Mathf.Abs(x - 0.5f);
z = Mathf.Abs(z - 0.5f);
// Hexagon constants
float a = 0.5f;
float b = Mathf.Sqrt(3) / 2f;
return a * z + b * x <= a * b;
}
Ended up finding another method by just calculating the distance to each cell from the center by traversing the grid
Hey guys i am getting Failed to enumerate registry keys, error code: 259 output in my code , shortly trying to get all subKeys of desired upper regedit key.
Any idea ?
private static UIntPtr HKEY_CURRENT_USER = new UIntPtr(0x80000001u);
private static uint KEY_READ = 0x20019;
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern int RegOpenKeyEx(UIntPtr hKey, string subKey, uint options, uint samDesired, out IntPtr phkResult);
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern int RegQueryValueEx(IntPtr hKey, string lpValueName, int lpReserved, out uint lpType, StringBuilder lpData, ref uint lpcbData);
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern int RegCloseKey(IntPtr hKey);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int RegEnumKeyEx(IntPtr hKey,uint dwIndex,StringBuilder lpName,ref uint lpcbName,IntPtr lpReserved,IntPtr lpClass,IntPtr lpcbClass,IntPtr lpftLastWriteTime);
{
GetSubKeys("SOFTWARE\\Unity\\UnityEditor\\DefaultCompany\\DefaultProject");
}
public void GetSubKeys(string parentKey)
{
IntPtr hKey;
int result = RegOpenKeyEx(HKEY_CURRENT_USER, parentKey, 0, 0x20019, out hKey);
if (result == 0)
{
Debug.Log("Key Open Success: " + parentKey);
uint index = 0;
StringBuilder subKeyName = new StringBuilder(1024);
uint subKeyNameLength = 1024;
while (true)
{
int enumResult = RegEnumKeyEx(hKey, index, subKeyName, ref subKeyNameLength, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
if (enumResult == 0)
{
Debug.Log("Subkey: " + subKeyName.ToString());
index++;
subKeyNameLength = 1024;
subKeyName.Clear();
}
else if (enumResult == 234)
{
break;
}
else
{
Debug.LogError("Failed to enumerate registry keys, error code: " + enumResult);
break;
}
}
RegCloseKey(hKey);
}
else
{
Debug.LogError("Key Open Error: " + parentKey);
}
}
ERROR_NO_MORE_ITEMS
259 (0x103)
No more data is available.
But when i check in regedit there is 3 entry like 🤔 @flint sage
else if (enumResult == 234)
seems wrong by the way
Check the error code says there's more data
Thanks @flint sage i will check the status codes again
How can I find a valid point in nav mesh with some range?
NavMesh.SamplePosition, is it OK?
I want to find a valid random point in specific range from a character
Valid point means the character can move and reach it
is this possible?
3 planes, with z of 0,1,2
0 - is a green plane
1 - is an orange plane
2 - is a see through plane that makes 1 see through if they overlap and doesn't affect 0
I'd imagine it's possible if 2 renders to a stencils, then 1 checks if the stencil is there and if so, doesn't render
#archived-shaders is probably a better place (i.e. you'd get better answers)
found https://www.youtube.com/watch?v=Blits1yymCw
which is pretty much what i want
is there any way to garbage collect System.Reflection data? According to Unity docs it is cached internally, and I would like it to be yeeted out of existence once I've done my thing with it
which docs are referring to?
To minimize the garbage collector overhead, avoid methods such as Assembly.GetTypes and Type.GetMethods() in your application, which create a lot of C# reflection objects at runtime. Instead, you should scan assemblies in the Editor for the required data and serialize and/or codegen it for use at runtime.```
We need game developers for a game called "Mortal Company" on the playstore made by unity, you should be experienced with coding in unity, you sadly won't be paid yet until the game gets famous.
dm me for more information
wrong channel buddy
Cant do that, however you can mitigate the GC overhead a little by keeping all of your reflection calls together and issuing them as soon as possible at game startup
That's fine - was hoping there was a secret way maybe, like inside of using scope, but I guess its not marked as IDisposable in the first place
No, it's static so lives for the life time of the application domain
You might be able to use reflection to clear the dictionary
Haven't really looked into it though
i guess that overhead only applies while during GC collection though? i don't think the unity GC does much work in the background, so during gameplay you would generally be avoiding that anyway
For il2cpp though, I doubt you can do anything
Also they're likely promoted to whatever gc level is not scanned often, so the impact is not that big
GC does a lot of work during gameplay, reorganising memory to makes larger contiguous memory available, this can cause a lot of overhead when you have lots of small allocations like reflection makes
i don't think unity's GC does any relocation does it?
well it's why memory fragmentation is a problem, unity has a doc page about it somewhere and i'm pretty sure unity has all the normal downsides as anything using boehm gc: https://paul.bone.id.au/blog/2016/10/08/memory-fragmentation-in-boehmgc/
In this article I explore an interesting memory fragmentation situation in the BDW Garbage Collector. This covers a program that crashes due to fragmentatio...
here's unity's page about fragmentation: https://docs.unity3d.com/Manual/performance-managed-memory.html
oh cool, but it says it only does it during collection, so the point is if you don't run GC.Collect a lot during gameplay, you probably won't run into this overhead much?
but the collection process runs every time you do an allocation which cannot be satisfied and/or periodically
hang on, that text you pasted is from the .NET docs, that's not the same GC as unity
yes it is, Unity uses the Mono GC which is the same as the .Net GC
from the doc you posted
you seem to have a rather odd understanding of this
i'm just reading the unity docs, it says right there it uses boehm 🤔
idk how it works in a mono build, but at least if you build to IL2CPP, it's not like there's a .NET runtime running as well somewhere in your game
but where do you think the IL comes from?
You're not running il either when using il2cpp
yeah, it boils down to c++, C# is basically a fancy template for writing C++ code in unity lol
Where the IL comes from doesn't matter at all, I can hand write IL, put it through il2cpp and it'll do GC operations on my objects just as fine
right, you can use boehm GC with normal C++ code too, if you look at generated IL2CPP that's all it's doing
the point I'm making is it's using the Mono .Net IL to create the cpp and thus the .exe so what is in the Mono Il ends up being run, whether that is a .Net envirnment or not
there's no GC inherent to C# the language though, you can run it without a GC if you really want to
Are you tlaking about the (basically redundant) mono runtime target?
Also it's running a customized roslyn compiler to generate the IL
no, how do you think IL2CPP works?
So what is generated has very little to do with mono
Well you're claiming that it's running mono IL, which is wrong since it doesn't exist anymore nor does it have anything to do with mono at that point, so I'm confused what you're talking about
Doesn't exist?
After a build obviously
from latest Unity LTS
Yes it's running the mono runtime in editor
unity uses the mono libraries, and i guess it embeds mono in the player in a mono build, but there's no mono runtime in an il2cpp build and according to the docs they use boehm even in mono builds
well what do you thing a build does? Have you ever looked at one?
From a Build
That's literally a mono build dude
the mono libraries are used in the build, either directly or by compiling them to C++, but the GC isn't part of the library, it's in the runtime itself
you don't compile the GC into your game, it's in unity already
il2cpp builds don't contain a managed folder
yes, and in A IL2CPP build all of those dll's are converted into cpp and put into one .exe, there is no difference to the runtime code
Right, this conversation is clearly not going anywhere, so I'm going to bow out
Is it possible to record a code driven animation in Unity? I have an pose created through inverse kinematics that I want to export as an animation but when I hit record it puts the character in T-pose
I'm having some problems using a render texture in to display another camera's output in a 2d game. Is there a compatibility issue with using render textures to output a second camera's view in 2d? The tutorials I've been finding have all been done in a 3d project rather than 2d.
I think the problem is that it by default sets up the material for a 3d environment using lighting and doesn't use 2D sorting order. I created a custom Shader from a few sources that is rendering the texture now. Remaining issue I think is related to the UVs of my custom mesh.
Late to the party. So you can’t just use System.GC APIs for even for reflections, then? What’s so special about reflection?
System.GC.Collect();
System.GC.WaitForPendingFinalizers()
yeah no GC collect doesnt work on reflection objects
Sorry if its not advanced enough lol ,
How do i assign an event to a public void in a script in my unity project so that other scripts can subscribe to the event?
What im wanting to do is intead of hardcoding interactions between a script and another one i want to be able to use an event that one can listen to to know when a specific method is called from the other
As long as you refer to methods as "public void" you shouldn't come even near #archived-code-advanced
Events tutorial: https://learn.unity.com/tutorial/events-uh
well it can only be a couple of things lol
Are you telling me you dont use public references?
I'm telling you I don't call methods "voids"
im just trying to explain my problem in the simplest of terms. But thank you for the tutorial.
I mean thats what a method in unity is though... To each their own i guess.
No it's not
void is a return type that means a method does not return anything. methods in unity are still methods, not "voids"
It's very common for methods to not return anything in basic Unity scripts but that's only in the very basic level
yeah i dont know what i was thinking lol
Thanks for the tutorial though i think i understand how to do it , I really need to start using delegates more... didn't even know you could encapsulate methods like that
HI there 😄 one question, if im loading addressables scene using async, should i make before the occlusion of all scene together and the navigation map?
If you're loading it additively, yes. Though, I don't know if that works the same way with Addressables loaded scenes.
do not cross post
I thought I had it in the wrong category, should I delete my other post?
yes
also this is a code channel, so posts should include the code involved. How can we know what you are doing on the basis of a screenshot?
I see.
Thanks so much I’m searching in documentation this and map nav mesh info also
Alright, more of a math thing, but I'm having trouble wrapping my head around rotations.
I'm currently trying to make an object follow another object's rotation, however, only the difference of when it starts
Which I have working. Kinda. my code records the initial rotation of both the controller object rotation and target object rotation, and applies the difference between the current controller rotation and the initial controller location to the target's initial rotation. ae:
Quaternion currentrot = caller.ownerController.transform.rotation;
Quaternion initialDifference = Quaternion.Inverse(initialObjectRot) * initialControllerRot;
rotDifference = Quaternion.Inverse(initialControllerRot) * currentrot;
if (toModify == null) {return; }
rotDifference = initialDifference * rotDifference;
targetRot = initialObjectRot * rotDifference;```
This works, but only if the normals are about the same direction, which isn't always the case. Any attempts I've made to solve this via offset (ae, add an offset to account for the difference between the initial controller dir & the initial object dir) just make it face the same direction as the controller instead of applying the same "relative" rotation.
Any suggestions?
I've tried using Quaternion.FromToRotation to a similarly dissapointing (arguably moreso) result:
```java
Vector3 initialControllerForward = initialControllerRot * Vector3.forward;
Vector3 initialControllerUp = initialControllerRot * Vector3.up;
Vector3 InitialObjectForward = initialObjectRot * Vector3.forward;
Vector3 InitialObjectUp = initialObjectRot * Vector3.up;
Vector3 ForwardDiff = (InitialObjectForward - initialControllerForward).normalized;
Vector3 UpDiff = (InitialObjectUp - initialControllerUp).normalized;
Quaternion currentControllerRot = caller.ownerController.transform.rotation;
Vector3 targetForward = currentControllerRot * ForwardDiff;
Vector3 targetUp = currentControllerRot * UpDiff;
targetRot = initialObjectRot;
targetRot *= Quaternion.FromToRotation(UpDiff, targetUp);
targetRot *= Quaternion.FromToRotation(ForwardDiff, targetForward);
```
I feel like it's a one line fix for either, I'm just not comfortable enough w/ Trig yet lol
nvm lol I just needed to inverse the difference and make the target rot the inverse of the diff applied to the current rot
heya, im trying to recreate this woodcarving effect by Daniel Beauchamp here: https://twitter.com/pushmatrix/status/1511331419896913920
but im running into a little bit of trouble at creating the shavings mesh, it works fine when the knife moves in the same direction as the stick, but when its at an angle, it either gets all weird and jank or really thin, and im really stumped as to how to get it working, any ideas?
You'll need to provide more details on the issues. Start with one issue and explain it in details. Providing a video could be helpful.
I'm having a lot of issue trying to build for WebGL.
Fatal error in Unity CIL Linker
System.NullReferenceException: Object reference not set to an instance of an object.
at Unity.Linker.Analytics.AnalyticsService.RecognizedReflectionAccessPattern(IMemberDefinition source, Instruction sourceInstruction, IMetadataTokenProvider accessedItem)
at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.MarkTypeForDynamicallyAccessedMembers(ReflectionPatternContext& reflectionContext, TypeDefinition typeDefinition, DynamicallyAccessedMemberTypes requiredMemberTypes)
at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.RequireDynamicallyAccessedMembers(ReflectionPatternContext& reflectionContext, DynamicallyAccessedMemberTypes requiredMemberTypes, ValueNode value, IMetadataTokenProvider targetContext)
at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.ProcessGenericArgumentDataFlow(GenericParameter genericParameter, TypeReference genericArgument, IMemberDefinition source)
at Mono.Linker.Steps.MarkStep.MarkGenericArgumentConstructors(IGenericInstance instance, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.MarkGenericArguments(IGenericInstance instance, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.GetOriginalType(TypeReference type, DependencyInfo reason, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementation(InterfaceImplementation iface, TypeDefinition type)
at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementations(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.MarkRequirementsForInstantiatedTypes(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
at Unity.Linker.Steps.UnityMarkStep.InitializeAssembly(AssemblyDefinition assembly)
at Mono.Linker.Steps.MarkStep.Initialize()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Unity.Linker.Steps.UnityMarkStep.Process(LinkContext context)
at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at Unity.Linker.UnityDriver.UnityRun(Boolean noProfilerAllowed, ILogger customLogger)
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(ILogger customLogger, Boolean noProfilerAllowed)
at Unity.Linker.UnityDriver.RunDriver()
UnityEditor.GenericMenu:CatchMenu (object,string[],int)```
Trying to implement SignalR using this guide here: https://prog.world/connecting-signalr-to-unity/
Using linker file still seems to give issues
Help optimise this LogHandler impl
hello, this my seem like a stupid question but i'm genuinely interested in the answer
Do customEditor scripts or in-editor tools get compiled or affect the build in any way (for example bigger built game) ?
No
as long as you porperly put them in an Editor folder or in an Assembly that is editor-only targetted
and what about OnDrawGizmos or OnValidate of MonoBehaviours ?
Does it get compiled ?
Gets compiled, yes, but never runs.
i guess i'd expect them to be likely to be stripped out of the final build, since they would have no callers in a player, but i haven't tested that
yes. Everything in those files gets compiled unless you wrap it in a preprocessor directive
Depends on how aggressive the managed code stripping is set to. By default, Mono doesn't strip anything, and IL2CPP strips only unused UnityEngine and .NET system library code.
true, so if you care about code size turn those settings up!
Does this mean debugging functions like DrawGizmos are included in production builds without using #if_DEBUG (or however it is formatted), and might affect performance/size even if unused?
yes
isn't that just a static image?
Here yes, i need to generate one in runtime when i switch bullets
Thank you
Anyone knows how to use the NCalc C# package with unity?
hi
either include the source code in your project, or compile it to a DLL and import the DLL into Unity
Know ow to import the dll to unity?
okay people, I think I need professional help becouse I can't find a solution anywhere... I'm trying to create a replay feature in the game, something like, everytime you die, but I also want them to be able to download the MP4 of the replay... how the hell do I do that? I've been looking everywhere, I found ways to record in editor and export in mp4, but I can't find a single tutorial in how to do this "IN GAME"
😬 that would be a really complicated feature
Certainly it would be prohibitive to record video in MP4 format all the time for all your players, so likely you'd want to do more of a keyframe-based replay system. But now you need to be recording keyframes for basically everything in your game that's visible all the time, and store them in some kind of buffer.
When you want to do a download as an MP4 it would have to trigger a resimulation of those keyframes and render the game and record it all to video... quite a demanding task in terms of compute resources.
don't need to worry about recording all the time, they told me they have a solution for that
my only job is making the capture system and making sure we can get a mp4 out of that
at least the only part that is missing on my part
I don't see anything that "they" are doing in this system if you are making the capture system and the export to mp4 system
seems like a huge task
well, the only part I need is to get a recording working, that has a defined start and end
showcase him, and then turn into a mp4
Know what this mean?
Maybe NCalc is already included in unity or something..
Looks like VisualScripting may be using it.
If you're not using VisualScripting feel free to uninstall that package
Hi everyone. Having a lot of trouble figuring out how to do something that seems like it should be simple through a Cloud Code C# module.
I want to set protected Player Data on players from the script. Can't figure out how to do it and Unity support has not been able to tell me.
https://docs.unity.com/ugs/en-us/manual/cloud-save/manual/concepts/player-data#
What are you refering to by "that package"
Visual Scripting
Btw do I have to add "Using NCalc;" on top of my scripts?
You really asking me that in #archived-code-advanced 🧐
The conversation has taken us here, that wasnt my initial quesion
As always, you can use using directives to eliminate the need to type out the fully qualified name of a type.
they are never strictly necessary
Alright, wanted to make sure that thats still the case for packages gotten from a dll
First time having to use C# libraries like NCalc lmao
im not 100% sure if this is the question to ask here but
im having an issue with finite state machine
i followed the official unity tutorial and its not working
heres the tutorial
this is my code:
https://pastebin.com/rapDMQzY
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
anyone know whats wrong?
my guy does not switch states
he just
patrols
only
{
stage = Event.UPDATE;
}```
Probably this, Unity probably calls that every frame
ah, so remove that?
i ended up removing it
he broke lol
added it back
still broke lol
Hi guys, I'm getting this error in Xcode when I try to make a build using Unity 2022.3.25:
Undefined symbol: __HasVibrator
It was not there in 2020. Has anybody else faced this issue before?
Visual scripting any state causes 2 states to run simultaneously, is there any fix 🤔
Version 1.8.0
just reading through it seems like there might be some confusion about Process & Update, as Navi mentioned. I'd perhaps consider changing what you want to be your manual "do this every frame while it's in stage UPDATE" call to Tick() instead, and make it clear what is being called by Unity automatically and what is your logic
I'd also expect your logic to move the stage along, but I don't see any of the Enter() calls pushing the stage to UPDATE. Adding some debug lines to print which stage you're actually processing at any given time will probably make it clear where the difference is between what you expect and what's actually happening
Hey Guys, currently I try to change some Outline Settings on runtime via C# and Precreated OutlinePresets. ut after some time - I have no idea how it works. Currenlty I tried something like this:
public class ChangeOutlineViaPreset : MonoBehaviour
{
public ListItem ListItem;
public UnityEditor.Presets.Preset Green;
public Object OOutline;
// Start is called before the first frame update
void Start()
{
if (ListItem.name.Contains("*green*"))
{
Debug.Log(CopyObjectSerialization(Green, OOutline));
}
}
// This method uses a Preset to copy the serialized values from the source to the target and return true if the copy succeed.
public static bool CopyObjectSerialization(Object source, Object target)
{
UnityEditor.Presets.Preset preset = new UnityEditor.Presets.Preset(source);
return preset.ApplyTo(target);
}
}
Can I map serverless different logins(Facebook, Apple, GooglePlay) to one Account in Unity.CloudSave ?
Hi, i've made a post in the unity forum, i'm sending the message here also to try reaching more people, in short i have the following issues :
- Long building process
- Maximum sampler issue with URP
- Graddle keystore issue
https://forum.unity.com/threads/multiple-issues-and-question-of-compiling-vr-game.1596960/
Thank you tons :)
can somebody help me achieve procedural walk animation like in unity example
-i just added a maximo model , and replicated this sample robot
What do you think about AI approaches in diplomacy strategy games?
I prefer HTN + utility over GOAP, what is you opinion?
The player has some neighboring countries. They can be friend/ally or enemy. The player can trade, invade, make sanction, change policy, customs, tariff, entry permit, etc.
and is there any framework/tool for HTN in unity like planner or I should implement it myself from scratch?
can someone please help?
https://forum.unity.com/threads/netcode-for-gameobjects-multiplayer-player-sync-problem-in-moving-spaceship.1597023/
Pretty sure you can get pretty far with simply assign weight to each possible action base on heuristic and "personality". GOAP is a bit more complicated and can be usefull when there is short to medium goal you have and want to have different method of achieving it.
Yes, it is true so you go with simple utility functions for each action? choose this way just one level search?immediate effect
That would be my approach, yes.
ofc, right now every frame i check whether each vertex has been cut by the knife, and if it does i move it do be flush with the knife,
i also want to create a shavings mesh out of the hit vertices, from the one thats been hit the closest to the top of the blade and one closest to the bottom something like this:
however, the problem is that most frames only one vertex gets hit, and what i'd like to do is somehow get the rows of vertices in realtime to i can create the mesh, so i'd like to know if anyone has an idea as to implement this i'd love to hear <3.
i've tried clumping them into groups, but it all turns out really jank
How are you creating the mesh? Are you sorting the vertices every frame before creating it?@pallid herald
If I have a monobehaviour or scriptableObject, which has a fields which are serializable classes, I can just edit them inline. However, can I also have them as null? So basically the user should be able to decide if he wants to populate that member or not
I see how I could do that with an additional boolean field
Unity's serialization doesn't support nulls
Nor nullable types
all classes are nullable or not?
but basically unity just gets rid of that?
ok then a boolean field it is
If you're mostly interested in the inspector you'd use a custom inspector or property drawer
yeah, but that seems like to much overhead
I think I'll just have the boolean field there and the other field visible always
I don't know if it just seems like it or if its true, but the inspector stuff seems to be quite lengthy for relatively simple things
seems to be done rather for proper extensions than for quick eye-candy changes
Use NaughtyAttributes you can do a lot with a little
ah nice, this looks great! thanks for the tip
Can anybody explain how RenderMeshIndirect works
and what do i need to make it spawn several meshes for me in some small bounds
Why my c++ not work:
print("hello world");
###############
#me build differenet#
###############```
How to youse turtle in c+#
is that related to my question?
Yes
Well, im not saying my code is not working
It's the solution
there is no code at all rn, only the declaration part
Ok but my solution work
I do
can you explain it a bit
Use tkinter.utilize.unityessentials in your first line of first c++ script
<@&502884371011731486> spam
Dont cry
there are already too many idiots in the server, we can do without any more
Then what are you doing here?
so well, I started with this
void Update()
{
Graphics.RenderMeshIndirect(rparams, mesh, buff);
}```
where
```csharp
public Material material;
public Mesh mesh;
private RenderParams rparams;
private GraphicsBuffer buff;
void Start()
{
rparams = new RenderParams(material);
// mesh and material are dragged to fields in Unity Editor
}
And my question is about how do i use buffer and what's it's purpose here
I read that GraphicsBuffer is used to store data inside the GPU, and that's the only thing i know rn
waiting to answer sensible questions, like every other helper
RenderMeshIndirect is a more complicated version of RenderMeshInstanced, where instead of feeding in the number of instances directly to the method, you do it indirectly through a GraphicsBuffer, which can be populated by a shader. But another reason people use the Indirect version is because RenderMeshInstanced has a max limit of 1023 instances, which the Indirect version doesn't have. Is that maybe why you chose the Indirect version?
yeah, my goal is to draw 100k grass meshes faster than rn
using just the RenderMeshInstanced
there are 60k meshes with around 60fps
it feels like a low amount
guys draw millions sometimes and even apply physics and still have more than 200fps
idk if that's because of alpha clipping or smth, but mesh has 16 verts in total(4 planes crossed making a star shape)
RenderMeshIndirect will not speed up the GPU performance of the draw call. But it can allow you to optimize everything needed to prepare the draw call, such as moving the instance calculations to a compute shader.
But before you do anything like that, you need to identify what the problem is before you can fix it.
well, main problem is idk if everything is optimized for calling draw(the mesh, the material, the texture, the project xD)
and second is the moving part
camera can rotate, also character can move
i don't really want to render everything outside of camera view + i want to apply LOD so grass far away will only have 8 verts instead of 16
Frustum culling and LOD calculations are best done with a compute shader, since it's an easy problem to parallelize.
well, my last attempt brought me to 40 fps
instead of 60
with lod and culling(it was bad)
i mean on screen it looked properly, but performance decreased
so you mean compute shader can help me change a mesh from one to another based on cam distance?
or i would need a read/write buffer and do the mesh change in a c# script
I'm a little worried about the terminology you're using. "spawn several meshes", "change a mesh". It's important to remember that all of this is stateless. After a draw call is finished, the GPU forgets about everything. The next draw call, though it might be identical, will be a brand new draw call to the GPU. Everything is done from scratch.
So "change a mesh" really just means choosing a different mesh when you prepare the next draw call.
alr, render several meshes, not spawn
Because you will have to choose a mesh every single time for every single instance.
and change a mesh means i have a position and mesh data(mesh number) in a buffer
so i need to change mesh data in this struct
Does anyone know how to configure the ExportContext in the UnityGLTF plugin so that it exports animations, because ExportOptions is now deprecated?
It's not impossible to render different meshes in a single instanced draw call, but it's not easy and likely not very performant. It would be easier to have a separate buffer and separate draw call for each LOD. Each extra draw call doesn't add much overhead. It's the total number of instance * vertex count that matters.
so well, i start with 2 separate buffers like fullResBuffer and lodBuffer
And then you would have a compute shader that will decide which buffer each grass instance will go.
then each frame i send a cam position to the compute shader and ask to place grasses in buffer1 or buffer2
You can create an Append buffer for this, which acts like a list with a max size.
i am extremely bad with append buffers
they just don't work for me for some reason
reason is i'm bad but still
i debugged stuff for hours trying to figure out why append buffer does some weird stuff when i read it's data
Give it another try. If you run into problems again, you can ping me here.
well, as i'm thinking
don't i need a third buffer
which represents set of all positions
just the float3
from which i select grasses and send to 2 smaller append buffers
How do you intend to generate the positions? Can the compute shader not do this too?
well
i created a GrassZone component and a visualiser for it
green box like collider
so i set the bounds for grass zone manually using object scale
script has a density value which just represents how many grasses are in this grass zone
so with current settings it's 100 grass meshes across a 300x300 plane
really low density
1 grass per 9 units or smth
That sounds like something a compute shader can do. You just give the compute shader information about the plane and density, and do the same logic as the script.
Then you can do a Dispatch for each Grass Zone.
what about the plane geometry
for generating positions i used my own code which used raycasts from above
and added a "GrassSupport" component
so some objects allowed grass growth on them like old moss-covered chests
@echo bloom There is no off topic here.
If you have nothing productive to add, keep it to yourself.
this way i fixed the problem with grass growing inside of objects
and also since set of positions is generated once on start, it's not a big deal
i just run the thing while showing user a loading screen
Ok in this case, yes, it makes sense to have a third buffer of positions, generated from these scripts.
Are you using RaycastCommand?
no, just the Physics.Raycast
what is a RaycastCommand
oh i see
async raycast batch
well, i will switch to it after i'm done with grass problem
right now i have a prefab for an empty mesh with a script for adding vertices to it, i then clump the hit vertices into groups and keep track of the right and left most vertices, and when a clump has enough vertices i add those left and right vertices to the mesh
can you join vc while i'm trying to code the grass thing
Sorry, no.
How are you sorting the vertices?
just by order of them being hit
'''void AddHitsToClump()
{
Vector3[] vertices = mesh.vertices;
foreach (int hitIndex in hitIndices)
{
Vector3 vertex = vertices[hitIndex];
Vector3 knifeCoords = knifeTracker.KnifeCoord(transform.TransformPoint(vertex));
float localX = knifeCoords.y > 0 ? knifeCoords.x : -knifeCoords.x;
CurrentClump.Add(nativeVertices[hitIndex], localX);
}
lastVel = knifeTracker.KnifeVelocity;
}'''
Well, that would explain weird mesh. You need to sort them properly to create a sort of plane.
yaya so im wondering if anyone's got any idea as to how to sort them
im thinking of maybe checking the z position relative to the movement direction of the knife
There're algorithms specifically for that purpose.
From quick google, Delaunay triangulation is one
That beings, said, there might be a simpler way, considering you know the orientation of the original mesh and it's vertices.
okie thx alot!
im just kinda new to the whole mesh generation so im not quite sure what to look for
Sure I will listen to you
private void UpdateDensity(int density)
{
this.density = density;
positions.Dispose();
fullResBuffer.Dispose();
lodBuffer.Dispose();
positions = new ComputeBuffer(density, 12, ComputeBufferType.Append);
fullResBuffer = new ComputeBuffer(density, 12, ComputeBufferType.Append);
lodBuffer = new ComputeBuffer(density, 12, ComputeBufferType.Append);
var results = new NativeArray<RaycastHit>(density, Allocator.TempJob);
var commands = new NativeArray<RaycastCommand>(density, Allocator.TempJob);
for (int i = 0; i < density; i++)
{
Vector3 randomPoint = new(Random.Range(-transform.localScale.x / 2, transform.localScale.x / 2), 4096, Random.Range(-transform.localScale.z / 2, transform.localScale.z / 2));
commands[i] = new RaycastCommand(transform.TransformPoint(randomPoint), Vector3.down, QueryParameters.Default, 8192);
}
JobHandle handle = RaycastCommand.ScheduleBatch(commands, results, density, density, default);
handle.Complete();
List<Vector3> coords = new();
foreach (var hit in results)
{
if (hit.collider != null)
{
coords.Add(hit.point);
}
}
positions.SetData(coords);
results.Dispose();
commands.Dispose();
}```
Make sure you dispose of the native arrays. You can just put using in front of var results and var commands.
Safer to use using, in case there's an exception and the bottom isn't reached.
alr
using automatically adds a try-finally block for you.
yeah i remember from java
commands[i] = new RaycastCommand(transform.TransformPoint(randomPoint), Vector3.down, QueryParameters.Default, 8192); this line breaks now
cannot modify the commands variable
Hmm, annoying. It doesn't like the fact that NativeArray is a struct. Then I guess you need to call Dispose yourself.
well
hi
I have a few extension methods like .Set(index, value) exactly for this purpose, so I can use using on native collections while still being able to modify them.
you mean it's some kind of downloadable wrapper stuff for native collections
or unity just has built-in .set() method in NativeArray class
No, just C# extension methods.
Is there a way to use the PlayerLoop class to insert something just before rendering like the native FrameEvents.OnBeforeRender? PlayerLoop.GetCurrentPlayerLoop() only seems to ever contain entries that stop just before frame rate matching. Is there a different process available for inserting into that portion of the loop?
stevesmith whats your age.
not that it's any of your business but I'll answer to > 65 but < 80
ok you are old dude.
that depends on your definition of old, to me everyone under 40 is a child. Are you a child?
😂
steve, its cool that u are making games at that age, i hope i wil never retire and just keep doing cool stuff then
from how long are you making games stevesmith.
u r an OG
lots and lots, and still do, not much you would know about though
i am under 40 only.
sweet
hobby or full time job?
Hey, I retired long, long ago, now I only do commisions
fun
I will let you into the secret of how to make money in the games industry. Don't make games, make frameworks and let others have the pain
😂 i think the trick is to go into ML or DS and game as a hobby, more fun and profits
Little or no profit for 99.99% of indie devs
right
Thanks, @upbeat path! Unfortunately, I am not working with MonoBehaviours in this case (ComponentSystemGroup in ECS) so I am unable to use the MonoBehaviour callbacks; although, I could probably use the Camera event and work it into the group to only update at that time. Just wish the PlayerLoop class actually covered the entire PlayerLoop. 😢
to make a framework is not that easy i used to make games using java in my past with lengthy lines of code.
you're right, frameworks are not easy but... you get to license them to multiple clients and reap the rewards of their endeavours
plus they pay for support, something sorely lacking in this industry
i think that is what godot is doing now.
they took brackey guy for their product advertisement and now he is doing publishing.
come on, all the children want is to make money, but they dont want to pay for anything, they expect support to be instant and also free, this is untenable
Well, shouldn't execution order be simpler with ECS? You have everything running in systems and you can insert your own system at any point or between any other system that you want.
its not about paying anything steve but it requires lots of hardcore programming. i have been through all programming languages c,c++,java ,assembly.etc mastered them but to build a framework it requires more programmers like me.
Well, first they need money and then they can pay for things.
let me ask you, how long have you been programming (and I mean programming not coding) professionally?
17 years.
Yes, if you need to run everything pre-frame rate matching/before render with a latency gap between simulation and rendering. Unfortunately, there is no ComponentSystemGroup running just before render to close that latency gap (which is important for things like XR) and there is not an easy way to insert one.
then you should know it's all about concepts. Software design and developement is an Art not a Science
yes.
So, like any art, there are those who can and those who can't, it's innate ability, that cannot be learned
I play guitar and piano, I paint and draw. I will never play at the Albert hall and I sure ain't no Picasso
Assuming you're using the Entity Graphics package, you can update your system just before the rendering system.
https://docs.unity3d.com/Packages/com.unity.entities.graphics@1.2/api/Unity.Rendering.EntitiesGraphicsSystem.html
No, you can't.
These seem to be 2 seaprate frames. What exactly are you trying to do?
Nope, that is one frame.
What makes you think so?
It would be really weird if the editor loop was pushed in between the player loop frame update.
i can't rly use an append compute buffer as a graphics buffer for RenderMeshIndirect
You're not supposed to. You're supposed to have a dedicated buffer that contains only your draw call arguments, like how many instances should be drawn and such.
how do i create one out of my 2 current buffers with positions for lod or fullres
After appending to your append buffers, you then use GraphicsBuffer.CopyCount to copy their counts to the draw call args buffer.
Target would be IndirectArguments. There's an example of this in the documentation page for RenderMeshIndirect.
fullResGBuffer = new GraphicsBuffer(GraphicsBuffer.Target.IndirectArguments, density, sizeof(myAss));```
i'll change the stride later on ig
when i get how many bytes element takes
It's in the example in the docs.
usually you can ask marshal to do it for ya
Yes
who's marshal
xD
so well, code looks like
void Update()
{
if (lastDensity != density)
{
UpdateDensity(density);
}
grassCompute.SetFloats("camPosition", cam.transform.position.x, cam.transform.position.y, cam.transform.position.z);
grassCompute.Dispatch(1, 1, 1, 1);
GraphicsBuffer.CopyCount(fullResBuffer, fullResGBuffer, 0);
GraphicsBuffer.CopyCount(lodBuffer, lodGBuffer, 0);
Graphics.RenderMeshIndirect(rparams, mesh, fullResGBuffer);
Graphics.RenderMeshIndirect(rparams, mesh, lodGBuffer);
}```
You can reuse the same args buffer because you'll only be able to do one draw call at a time. So you can set it up as:
Initialization:
1. Create and initialize grass positions buffer.
2. Create fullRes and lod append buffers.
3. Create draw args buffer.
Update:
1. Clear fullRes and lod append buffer counts.
2. Dispatch compute shader to append to the append buffers.
3. Copy fullRes count to draw args buffer.
4. RenderMeshIndirect fullRes.
5. Copy lod count to draw args buffer.
6. RenderMeshIndirect lod
i don't get the Update step 1
Oh, you're still on the grass thing. I was looking at Unity 6 today and they were introducing a bunch of tools like that GPU indirect culling you were looking into
The append buffers will still have their counts from last frame. You have to clear them back to zero.
GraphicsBuffer.SetCounterValue(0)
so
grassCompute.SetFloats("camPosition", cam.transform.position.x, cam.transform.position.y, cam.transform.position.z);
grassCompute.Dispatch(1, 1, 1, 1);
GraphicsBuffer.CopyCount(fullResBuffer, gBuffer, 0);
Graphics.RenderMeshIndirect(rparams, mesh, gBuffer);
GraphicsBuffer.CopyCount(lodBuffer, gBuffer, 0);
Graphics.RenderMeshIndirect(rparams, mesh, gBuffer);```
i reuse the same gBuffer
first for full res and then for lod
but fullRes and lod are compute buffers (AppendBuffer in compute shader)
aren't they
You can use either. GraphicsBuffer is a more recent, more general version of ComputeBuffer.
so one extends another
No, ComputeBuffer came first with a more specific use case. Then they made GraphicsBuffer which can represent any kind of buffer on the GPU, including what ComputeBuffer was doing.
alr i reset to 0
then send cam position
then copy count from fullres to g
then render
then copy count from lod to g
and render again
Ok, it looks like you're not initializing the draw args buffer correctly. This is what the struct is:
public struct IndirectDrawIndexedArgs
{
/// <summary>
/// <para>The number of vertex indices per instance.</para>
/// </summary>
public uint indexCountPerInstance { get; set; }
/// <summary>
/// <para>The number of instances to render.</para>
/// </summary>
public uint instanceCount { get; set; }
/// <summary>
/// <para>The first index to use in the index buffer of the rendering call.</para>
/// </summary>
public uint startIndex { get; set; }
/// <summary>
/// <para>The index to add to values fetched from the index buffer.</para>
/// </summary>
public uint baseVertexIndex { get; set; }
/// <summary>
/// <para>The first instance to render.</para>
/// </summary>
public uint startInstance { get; set; }
}
With this: GraphicsBuffer.CopyCount(fullResBuffer, gBuffer, 0);, you're copying the count of fullResBuffer to the first byte offset, which is indexCountPerInstance. That's not correct, you want to set instanceCount, which is the second argument, at byte offset 4.
indexCountPerInstance should be set to the triangle count of the mesh. The last three can be zero, which they are by default.
wait
i need to get it
im using 100% of my brain rn
sss... so
I can make postions, fullRes and lod buffers GraphicBuffers
right?
since graphic buffers can have type of append or structured
You can.
There's no performance improvement to be gained. It's just a different API to get the same thing. But you might end up in a situation where a newer method only accepts the newer GraphicsBuffer, so it's usually best to use that.
well
But if you haven't run into that problem, you don't need to hurry to change it now.
private GraphicsBuffer positions, fullResBuffer, lodBuffer;
positions = new GraphicsBuffer(GraphicsBuffer.Target.Structured, density, 12);
fullResBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, density, someSize);
lodBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, density, someSize);```
i have
problem with my knowledge and understanding
so well, pos buffer is just a ton of float3
XYZ
and what should fullRes and lod contain?
not only a position, but also a vertex count or smth
or i'm going in completely wrong direction
Information about the mesh won't be necessary, because that's already handled by Unity. Do you have a custom shader on the grass or do you intend to use built-in shaders if possible?
@deep jasper It's best if you use a custom shader. Otherwise, you need to prepare the data in the specific format that Unity's shader expect them to be in, which isn't going to be the most memory efficient.
just the built-in with alpha clipping by now
Which render pipeline are you using?
urp
hdrp is too hard for me now
URP lit if you want the name of the shader
i can do my own less complex shader in shadergraph
with only alpha clipping value and texture2d input
Ok. Shader Graph is the easiest way to make a lit shader in URP. Hand written shaders need a lot of boilerplate just to get a basic lit shader. But GPU instancing support for Shader Graph is a bit weird. I think it's possible, but there's no docs for it.
https://forum.unity.com/threads/shadergraph-instancing.1339943/
Some weird steps you need to take to get it work. No idea if this still works.
I wouldn't recommend it in URP if you want lighting support.
So even though the Shader Graph route seems a bit weird, I would still recommend trying that first.
Try following the steps in the thread I sent you. If you run into issues with that, I would suggest moving over to #archived-shaders and asking there. A lot of Shader Graph experts there who know more than me.
steps in this shader are not rly using texture tho
It's only showing the steps required enable instancing support, read from a structured buffer with the right index and returning some value in a Custom Function node, which you can then use however you want in the graph.
For example, the Custom Function node could return the float3 position for this grass instance, which you can then add as an offset to the Object Space Position (i.e. vertex position)
That's the wrong menu. Look in the Shader Graph menu.
A .hlsl file. There's no Create Asset menu item for it, it's just a text file with the .hlsl extension.
I think it's created in the Blackboard, like a property.
for me it's
That looks fine.
Sure. It's just a hack to ensure that bit of code runs.
well, it's done
public class GrassZone : MonoBehaviour
{
public Material material;
public Mesh mesh, lodMesh;
public int density;
private int lastDensity = 0;
private RenderParams rparams;
private GraphicsBuffer positions, fullResBuffer, lodBuffer;
private GraphicsBuffer gBuffer;
private ComputeShader grassCompute;
private Camera cam;
private void Start()
{
UpdateDensity(density);
rparams = new RenderParams(material);
cam = Camera.main;
gBuffer = new GraphicsBuffer(GraphicsBuffer.Target.IndirectArguments, density, GraphicsBuffer.IndirectDrawIndexedArgs.size);
}
void Update()
{
if (lastDensity != density)
{
UpdateDensity(density);
}
fullResBuffer.SetCounterValue(0);
lodBuffer.SetCounterValue(0);
grassCompute.SetFloats("camPosition", cam.transform.position.x, cam.transform.position.y, cam.transform.position.z);
grassCompute.Dispatch(1, 1, 1, 1);
GraphicsBuffer.CopyCount(HOW); // HOW
Graphics.RenderMeshIndirect(rparams, mesh, gBuffer);
GraphicsBuffer.CopyCount(HOW); // HOW
Graphics.RenderMeshIndirect(rparams, lodMesh, gBuffer);
}
}```
and that's the code which runs in the beginning
private void UpdateDensity(int density)
{
lastDensity = density;
positions.Dispose();
positions = null;
fullResBuffer.Dispose();
fullResBuffer = null;
lodBuffer.Dispose();
lodBuffer = null;
positions = new GraphicsBuffer(GraphicsBuffer.Target.Structured, density, 12);
// ITS PROBLEMATIC
fullResBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, WHAT IS THE SIZE HERE, WHAT IS THE STRIDE HERE);
lodBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, WHAT IS THE SIZE HERE, WHAT IS THE STRIDE HERE);
// I DON'T GET IT
using var results = new NativeArray<RaycastHit>(density, Allocator.TempJob);
var commands = new NativeArray<RaycastCommand>(density, Allocator.TempJob);
for (int i = 0; i < density; i++)
{
Vector3 randomPoint = new(Random.Range(-transform.localScale.x / 2, transform.localScale.x / 2), 4096, Random.Range(-transform.localScale.z / 2, transform.localScale.z / 2));
commands[i] = new RaycastCommand(transform.TransformPoint(randomPoint), Vector3.down, QueryParameters.Default, 8192);
}
JobHandle handle = RaycastCommand.ScheduleBatch(commands, results, 1, 2, default);
handle.Complete();
commands.Dispose();
List<Vector3> coords = new();
foreach (var hit in results)
{
if (hit.collider != null)
{
coords.Add(hit.point);
}
}
positions.SetData(coords);
}```
Is there a way to get on-screen keyboard height on mobile?
Users can scale it any way they want, so it's probably handled by OS
you can try tracking screen.width or height
screen height doesn't change when the keyboard is opened, size from here https://docs.unity3d.com/ScriptReference/TouchScreenKeyboard-area.html is 0 on android, as mentioned in the doc
no clue then
Ok, so now you need to decide on what data you want to send to the shader. The bare minimum would be for each grass instance to get a Vector3 world position. Since you already have a buffer that contains all of the positions, it would be ideal to just read from that. So fullResBuffer and lodBuffer can contain indices that map to the positions buffer.
The Custom Function node which reads the _PerInstanceData would look something like this:
StructuredBuffer<float3> _GrassPositions;
StructuredBuffer<int> _GrassIndices;
void GetInstancingPos_float(in float3 PositionWS, out float3 Out)
{
Out = 0;
#if UNITY_ANY_INSTANCING_ENABLED
int grassIndex = _GrassIndices[unity_InstanceID];
Out = PositionWS + _GrassPositions[grassIndex];
#endif
}
To be able to read the AppendBuffer like it's a StructuredBuffer, you'll need to add the Structured flag to it. It can be marked as both.
new GraphicsBuffer(GraphicsBuffer.Target.Structured | GraphicsBuffer.Target.Append, ...)
as i'm thinking
why do i need a custom shader
if anyways to draw a mesh using RenderMeshIndirect, i pass both mesh and material as params to the method
i can just tick gpu instancing in URP lit to true
Because with RenderMeshIndirect, Unity has no information about where each instance needs to be rendered. Unlike RenderMeshInstanced, where you pass in an Matrix4x4 array.
thanks i get it now
so this code you sent goes into compute shader or the grass shader
default generated stuff
I was showing how you might read the data in the .hlsl file which is used in the Shader Graph.
so grass shader's hlsl part
I have a .. weird bug that I can't seem to figure out. I'm getting a MissingReferenceException but only after I'm using a debug tool to reload a scene. When I click through the error and examine the hierarchy, everything seems to be in order, and there's no weird DDOL or anything on any related component/GOs.
It's failing on a TryGetComponent() call within the object, but.. the stack trace doesn't make any sense to me.. Any ideas on what to pull apart?
Just so we're clear - I've debugged many many NREs and MREs and usually it's obvious what the problem is, but this one's strange.. The line of code that it fails on doesn't even seem related..
(I know this isn't a lot of info to go on but I'm not exactly sure where to even look for this one)
I can recreate and record a video in the editor if that's helpful, maybe
SimpleCancelDialog is just a full screen "click catcher" with a callback - but you can set the default color of it in case you wanted to change it at runtime or in a tween
https://pastebin.com/wBQf6g7s Here's the full stack trace, and I'm happy to show any code you want.. but this one's super weird to me
You could try adding a conditional breakpoint on that line that checks if this == null
private void InitColor()
{
if (_image != null) return;
if (!TryGetComponent(out _image)) // problem
{
w("SimpleCancelDialog contains no image and will not work.");
}
}
Here?
(that's the "bottomest" line in the stack trace)
Yes, on the TryGetComponent
That's an implicit call to this.TryGetComponent, so this must be considered destroyed.
I'm gonna start from ShowVictory() and dive in.. but all these items in the inspector are defined, and I don't think there's anything in the scripts unsetting inspector references
This can happen with events, if you forget to unsubscribe from an event before the object is destroyed.
hm.. it might be event related
I'm not unsubbing from the action in OnDestroy
(from the parent)
well MissingReference is explicitly about using a Destroyed object, so it wouldn't be that
yeah that'll do it
lemme paste some code, maybe this is the problem:
UnityEngine.Events.UnityEvent.Invoke () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
Coffee.UIExtensions.UIParticleAttractor.Attract () (at ./Library/PackageCache/com.coffee.ui-particle@6d8dee0b06/Runtime/UIParticleAttractor.cs:144)```
looks like an event subscriber
that probably wasn't unsubbed
public class GameOverRenderer : BetterMonoBehaviour
{
[SerializeField] private SimpleCancelDialog SimpleCancelDialog;
public void ShowDefeat(GameDefeatEventArgs _)
{
SimpleCancelDialog.Initialize(() => OnCancelClicked());
}
}
public class SimpleCancelDialog : BetterMonoBehaviour, IPointerClickHandler
{
public void Initialize(Action callback)
{
_callback = callback;
}
}
wiill that break if GameOverRenderer doesn't unsub?
like - will it prevent the GO from being destroyed..?
If whatever invokes _callback lives longer than GameOverRenderer you'll get a MRE when you try to invoke it
no nothing will prevent that
i'll dig, thanks.. that's at least a clue in the right direction
RuleOfCoolStudios.TwentyFortyEight.GameScreen.OnAllGoalAnimationsComplete () (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Screens/GameScreen.cs:251)
RuleOfCoolStudios.TwentyFortyEight.GameRenderer.GoalUpdatedCallback (System.Int32 goalIndex, System.Int32 beforeAmount, System.Int32 afterAmount, System.Int32 remainingAmount) (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Game/GameRenderer.cs:652)
RuleOfCoolStudios.TwentyFortyEight.GameRenderer+<>c__DisplayClass96_0.<OnGoalContributed>b__0 () (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Game/GameRenderer.cs:614)
RuleOfCoolStudios.TwentyFortyEight.ParticleSystemWithAttractor.OnAttractedCallback () (at Assets/Scripts/RuleOfCoolStudios/2048CE/VFX/ParticleSystemWithAttractor.cs:38)
UnityEngine.Events.InvokableCall.Invoke () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
Coffee.UIExtensions.UIParticleAttractor.Attract () (at ./Library/PackageCache/com.coffee.ui-particle@6d8dee0b06/Runtime/UIParticleAttractor.cs:144)```
Looks like there's 3-4 event-handler style things in this stack trace. I would check each of these event subscriptions and make sure they're all being cleaned up symmetrically.
yeah.. i originally wrote an extension for it but it wasn't helping.. my "usual" pattern isn't great either since it's hard to see missing unsubs:
This is all because C# doesn't care that an object gets destroyed. Everything in C# stays alive until nothing references it anymore and it gets garbage collected. So it will happily invoke an instance method on a destroyed MonoBehaviour if you tell it to.
RuleOfCoolStudios.TwentyFortyEight.GameScreen+<>c__DisplayClass43_0.<OnGameVictory>b__1 () (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Screens/GameScreen.cs:246)
What about this one?
Looks like it's a lambda maybe?
ie - sub in OnEnable unsub in OnDisable has worked for me
Yeah that's good
checking that .. but it seems correct
fuck.
spot the bug
genius crew as usual, thanks guys. 🙂
Oh dang. Just that one operator
yep - double subbed instead of unsubbing
nice
ahhh yeah that's brutal haha
took me a second to see it
this exact syntax bug has gotten me a handful of times over the years and I ... don't have a better pattern for this approach
Any ideas?
also it makes me sad that those aren't in the same order haha
i will fix that - usually i put them in the same order for exactly this reason
Write a Roslyn analyzer and send it to me pls
you know, a few months ago i tried to write one but it was too complex for my caveman brain
I've seen libraries use a Dispose pattern for event subscriptions and a way to combine multiple subscriptions into one disposable.
i probably should do some sort of extension in my BetterMonoBehaviour that has something like a signature of
public void AddSubscriber(delegate T delegateEvent, Action eventHandler);
that does somethign like add delegates and handlers to a list and then subscribes to everything in the list in OnEnable and unsubs in OnDisable but .. I don't know if I could get the generic part of it working
like, I'd love to be able to do something like:
public class SomeRenderingComponent : BetterMonoBehaviour
{
private void Awake()
{
AddSubscription(GameManager.GameDefeat, OnGameDefeat);
}
}
(and then the end result would be the same, without the high chance of fucking it up)
in any case, awesome job @sly grove as usual, add a beer credit to the tab
(and you @sage radish ❤️ )
I'm glad I don't have to deal with these issues because my game runs entirely on reactivity system, so things automatically unsub without me needing to write a single line of code that could mess it up or forget.
UniRx?
No, it's my own much lighter reactivity system.
Here's the basic idea: #archived-code-advanced message
I suppose I ought to explore something like this in the future.. but in general I like how I can loosely couple singleton domain logic classes with all of the UI
when you have a large list/array in the unity inspector it auto adds a scroll bar anyway to get rid of that functionality, or control at what size it happens? do i have to make a custom editor function to display things a certain way instead
Yeah exactly - that's what I was thinking.. although a lot of my events are sourced and use EventHandler<CustomArgsClass> style signatures
it works for Action but would need to be genericized for different signature events
Yeah this feature requires a lot of buy in from the project, you pretty much have to build your entire project around using Signal.
public class GoalUpdatedEventArgs : EventArgs
{
public int GoalIndex { get; set; }
... etc ...
}
public partial class GameManager : ReloadableManager
{
public static event EventHandler<GoalUpdatedEventArgs> GoalUpdated;
}
... elsewhere in a rendering component.. ...
private void OnGoalContributed(object sender, GoalUpdatedEventArgs args) {}
that way all the events can have a huge number of named parameters instead of needing to do nonsense like Action<int, int, string, int, SomeEnum> and remember to get the things in the right order
If you're using the inspector a lot for lists like this, I'd probably explore an aftermarket inspector solution like OdinInspector
It doesn't matter what signature you use, as long as you have one single place where you subscribe to all events, which you can hook into, then you can build the auto unsub clean up.
just checked it out going to have to get it has lots of great features. thanks
I have a prefab that consists of Slider and Buttons. A UIManager instantiates bunch of gameObjects at runtime. I need a way for buttons to get the information of Slider Value. Usually, I'd use something like, transform.find() but that only searches for child gameObjects which is not the case here. I can't do GameObject.Find() because similar objects (and name) for each of the dynamically created objects.
I think using events is a way to go but All the tutorials that I have seen don't really address how to use events during run time. It's easy to use unity events and drag and drop references in the inspector. But it's not possible when you are instantiating objects at runtime.
Not sure this is advanced, but its not busy right now. Id say, if you instantiate the thing from UI manager, you just give it a setup function where you pass in the desired slider as a param, so you tie two things together.