#archived-code-advanced
1 messages · Page 6 of 1
I'm making a ton of menus.
There's reasons I'm pooling.
Isn't this an advanced channel? 😄
Yes. Sometimes people think it's a good idea to make things like card games purely out of UI elements though
Just don't understand the value of saying "Would be crazy of I was making a 2D game" as if that meant anything. What does making a 2D game have to do with UI? There can be 2D games with almost no UI, and 3D games with tons of UI.
It is also possible to have conversations without sounding entitled and sarcastic. Usually gets your question answered faster.
Because you're assuming I am making a game without UI?
And it's also possible to answer a direct question as opposed to sounding like you know anything I'm creating and assuming I'm wrong because I'm pooling UI. Not only is that arrogant it's also not helpful.
We're in Advanced chat are we not? Why do you automatically assume people don't know what they are doing? Is that a insecurity about your own skills?
My game has UI but does not use Unity's UI system
My entire game is UI.
Have you read this? https://unity.com/pt/how-to/unity-ui-optimization-tips
People often pool UI objects by reparenting and then disabling them, which causes unnecessary dirtying.
Solution: Disable the object first, then reparent it into the pool.
You will dirty the old hierarchy once, but once you reparent it, you’ll avoid dirtying the old hierarchy a second time – and you won’t dirty the new hierarchy at all. If you’re removing an object from the pool, reparent it first, update your data, and then enable it.```
That article has a lot of useful tips on the matter
Yes I'm aware of that thank you.
Class A (which I made) won't recognise class C (a Unity class) but class B (which I didn't make) can, even though A and B both use the namespace that C is part of. Why could this be happening?
I've heard it might be something to do with assembly definitions, but I don't know enough about that to actually figure out a solution.
Well if your code is in a custom assembly (even if it was an accident), you would need to reference the Unity assembly that contains class C. This is probably what class B did.
Hard to give a definitive answer with so little information.
yeah sorry I can't show my code or anything, this is for professional work and I'm under an NDA
How would the class reference the appropriate assembly? Maybe there's some syntax in class B that I haven't noticed?
e.g. the syntax used
No it's a separate file
If assembly definitions are present, it has nothing to do with the code itself.
Anyways, read the docs to figure out how they work and see if you have any
@flint sage @gentle topaz so how would I actually figure out which assembly definition a class belongs to? I searched for all the files with the .asmdef extension, but there's a ton of them and none of the names seem to correspond to stuff in the B class
Asmdefs apply to the folder they're in and sub folders, check your project structure
so if I've got this right:
I should look for B and check the folder it's in, to see the assembly definition it's part of.
Then I should either make a new assembly definition for A that has the same references as B, or move A into the same folder as B?
Something like that yeah
If you didn't make the code for B (as in it's third party), I would go for the first option (or find whatever existing assembly that its part of and add the references there)
@flint sage okay I didn't find one in the exact folder, but I backed up two parent folders and found an .asmdef file that seems to be related to that code.
B isn't third party, it's part of the same project, but it was created by someone else who's left now (I'm their replacement).
well fuck you then Unity
I opened the asmdef and all the references are arbitrary strings of hexadecimal values, all preceeded by GUID:
You don't want to open it in a text editor..
It has an inspector where you can configure all the references and build targets
@gentle topaz okay I think I found the file in the editor and opened it in the inspector
back in 5 mins
Hey guys, i did a code to add items to inventory, it has a system to handle the maxstack per item, for example HP Potions maxStack can be 30 and leather can be 500 and equipments 1.
I have a problem because when the bag is almost full the game breaks for a second to do the code, cause of the complexity i've done it.
Anyone knows how can i optimize this?
public void Add(Item item,int nItems){
int rest = nItems;
if(Items.Find(i => i.id==item.id && i.qnt < i.maxStack)!= null){
foreach(Item i in Items){
if(i.id == item.id && i.qnt < i.maxStack && rest > 0){
if(i.qnt + rest > i.maxStack){
rest = i.qnt+rest - i.maxStack;
i.qnt = i.maxStack;
}else{
i.qnt += rest;
rest = 0;
}
}
}
}
if(rest>0){
do{
Item i = item;
if(rest > i.maxStack){
i.qnt = i.maxStack;
rest -= i.maxStack;
}else{
i.qnt = rest;
rest = 0;
}
Items.Add(i);
}while(rest>0);
}
}
@gentle topaz okay so I wasn't able to figure out exactly what I needed, but I copied and renamed that existing assembly definition, and now the reference seems to work?
@gentle topaz thanks
Hello trying to deserialize null to default value for value type variables, is there any easy way to do so with Newtonsoft (I am not sure if i am on right way but tying to find answer here > https://www.newtonsoft.com/json/help/html/NullValueHandlingIgnore.htm < )
I dont like this 2 solution
trying to find better one
Value types cant be null unless they're nullable value types
Hey guys, I am trying to get collision surface normal (normal vector) to fire explosion in that direction. I am using onCollisionEnter(Collision col) to get collision normal via col.GetContacts(0).normal, however when I draw the ray in Scene view the normals are completely off, always pointing in forward direction (slightly randomly).
Surfaces the capsule hits vary (some are planes, some are triangle-segmented spheres etc.). At the end of the day it always hits the flat surface, therefore there should be no problem with normals. Any help would be appreciated 🙂 (an example below is how I imagined it to be)...sorry for spamming, was not sure whether this belongs in #archived-code-general or #archived-code-advanced
Can you post the code where you draw the normal for debug? Depending on the method there are small differences to the arguments you need to pass.
Normals were always accurate for me, so I suspect the issue is on the debug draw
Also don't cross-post
deleted the post in #archived-code-general
@fresh salmon void Explode(Collision collision) { Quaternion ExplosionRotation = Quaternion.FromToRotation(Vector3.forward, collision.GetContact(0).normal); Debug.DrawRay(transform.position, collision.GetContact(0).normal*100f, Color.red, 10f); GameObject explosion = Instantiate(Explosion, transform.position, ExplosionRotation); explosion.GetComponent<Explosion>().IsOpponent = IsOpponent; Destroy(gameObject); }
I save the collision from onCollisionEnter() and pass it in Explode()
Alright gotta check the docs one sec
collision.GetContact(0).normal is different from the surface normal
probably use a raycast or something to get the surface normal
And transform.position as the origin point of the debug ray seems wrong
Surely you would pass the hit point in there
thats the whole point why i am trying to deserialize json to default value and not null
This is the Grenade gameObject with Explode() function rather than Explosion gameObject with Explode(). transform.position gives the correct coordinates of explosion, no issue there.
Oh, is that so? 😮 Hmmm ..However, I do not have collider/rigidbody on the surface it hits, I only have a layer. I assume that will be an issue.
What is the most convential way of getting the surface normal upon collision? Is RayCastHit the only way?
I wonder how you get your Collision parameter then
Because you usually get that from OnCollisionEnter, and without a collider on both surfaces OnCollisionEnter doesn't run
So this is a grenade that sticks to the surface and explodes. I have Update() in which I have a coroutine that regulates when it's the time to trigger Explode(Collision collision). I also have OnCollisionEnter(Collision collision) in which I get collision, it is saved as protected Collision collision globally in the Grenade.cs file.
this is all the logic
Yeah, but
I do not have collider/Rigidbody on the surface it hits
With this information, I'm pretty sure your OnCollisionEnter never runs
Mhm, there was a mistake on my end. There is a Mesh Collider. 😄
Ah alright
This is the dome the player on that podium can hit. The grenade sticks to the surface (becoming Kinematic when onCollisionEnter() is triggered)
Can you try:
Quaternion explosionRotation = Quaternion.LookRotation(collision.GetContact(0).normal);
For the rotation calculation? This assumes the local Z axis of the explosion prefab points outwards, ie. the particles of the explosion go towards their Z axis
Correct, for the rotation. I am looking for the rotation essentially with the normal. I will try it now. Thank you
Ask the question
nothing i just fixed the problem right a few seconds ago
thx for the reply
lol alr
The explosions explode in different directions, less consistent than before.
Could the rotation of the projectile (i.e. grenade) hinder the normal vector?
Or does the Collision collision parameter in callback OnCollisionEnter() account for the angle in which it came in? Maybe that scuffs the normal?
Nah it should stay consistent whatever the angle of the object is, if you didn't do that yet can you try setting the Rigidbody's collision detection mode to "Continuous Dynamic"?
Surface or grenade projectile or both?
Itll put more load on the physics engine, but you can't get collisions that are more accurate than this
Grenade, as it's the one with a Rigidbody
Already on Continuos Dynamic.
I'm out of ideas then...
Looks good to me
Ironically, it never rotates correctly exactly, so there must be a major flaw. Could be that some colliders are not that well interactable with each other (i.e. Mesh and Capsule collider)?
...this is how it happens usually
where e = actual explosion direction
sometimes it hits ok, sometimes like this..it's like a Russian roulette 😄
The worst case scenario I will have to switch to radial explosions but that would be a defeat on my end
Hello there, recently I am encountering an editor crashing issue that happens both in Editor Play mode and Runtime
here is the editor generated crash log:
=================================================================
Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at UnityEngine.Transform:SetParent <0x00156>
at UnityEngine.Transform:SetParent <0x00092>
at DEYU.AdpUISystem.Managers.AdpUIPannelManager:PrepareBufferedPannel <0x0028a>
at DEYU.AdpUISystem.Managers.AdpUIPannelManager:PrepareBufferedPannel <0x000ca>
at Common.UI.UniversalGameManager:OpenDialogMenu <0x001da>
at Common.TimelineExtestion.COM_ADialog_Play_Behaviour:OnBehaviourEnter <0x0018a>
at Common.TimelineExtestion.ExtendedPlayableBehaviour:OnBehaviourPlay <0x0013f>
at <Module>:runtime_invoke_void__this___Playable_FrameData <0x00259>
at <unknown> <0xffffffff>
at UnityEngine.Playables.PlayableDirector:Evaluate <0x00140>
at Common.TimelineExtestion.GameTimeManager:Update <0x002fa>
at System.Object:runtime_invoke_void__this__ <0x00187>
=================================================================
Received signal SIGSEGV
Obtained 54 stack frames
0x00007ff60bd7cbfd (Unity) UI::CanvasRenderer::UpdateParentHierarchyChange
0x00007ff60b56c01f (Unity) TransformHierarchyChangeDispatch::DispatchSelfAndAllChildren
0x00007ff60b564c0b (Unity) Transform::SetParent
0x00007ff60aa8a188 (Unity) Transform_CUSTOM_SetParent
<Other Log>
In runtime it looks like:
========== OUTPUTTING STACK TRACE ==================
0x00007FFF1432B093 (UnityPlayer) UnityMain
0x00007FFF1431CB44 (UnityPlayer) UnityMain
0x00007FFF143285F0 (UnityPlayer) UnityMain
0x00007FFF14328B54 (UnityPlayer) UnityMain
The piece of code that produce the specific issue is:
@trail cloak Which unity version do you have
2021.3.6f1
LTS
public static T PrepareBufferedPannel<T>(GameObject pannelParent, Action<T> preInitializeCallback = null) where T : UIPannelBase
{
T pannelInstance;
if (Instance.m_BufferedPannel.TryGetValue(pannelParent, out var pannelInstanceSrc))
{
pannelInstance = (T)pannelInstanceSrc;
var parent = ActivePannelTransform.Peek().Root;
//Debug.LogError("Get Pannl To Transform: " + parent.name, parent);
pannelInstance.transform.SetParent(parent);
if (Instance.m_BufferedPannelRectTransform.TryGetValue(pannelParent, out var data))
{
data.ToRectTransform((RectTransform)pannelInstance.transform);
Instance.m_BufferedPannelRectTransform.Remove(pannelParent);
}
pannelInstance.gameObject.SetActive(true);
}
else
{
pannelInstance = GenerateBufferedPannel(pannelParent, preInitializeCallback);
}
return pannelInstance;
}
pannelInstance.transform.SetParent(parent);
This line is where the issue happens
However this method is widely used under different scenarios, and I failed on finding any useful information about it.
This particular error is versioning error of Unity
versioning error??
May I have a more detailed definition on this word? (I'm non-native speaker
It happens due to limitations sometimes on particular version, however the odds are it could be something else
As in that the error only shows on that version.
Correct
I see... I'm going to upgrade/downgrade the project and try again
How long have you been using this version, has the version gotten any updates?
This is an LTS version... which been released recently
Did you edit the any of the source projects files by any chance..changing guid or something
did it run ok before on this version
if it was released recently, it could have gotten a patch by developers that caused the bug
@trail cloak Another thing, try looking in Package Manager for any errors (instead of a green tick, it will have a yellow sign or red stop sign)
@trail cloak wait, wait...
you have a stacktrace error 😄
One of the parents or children is null
But.... a null reference parent can crash the unity sounds...
weird
I will try to log it
Check if ActivePannelTransform is empty
because you do not seem to get the root/parent
SetParent() probably does not accept null values is my guess
wait.... it stops crashing after I added the check
obviously, but the question still remains
Why is ActivePannelTransform null or empty? Where do you get it
Correction, not the check, I added the log
Hmmm
if it works, you have a caching issue
LogError logs into error stream, thus ignored but packed in the error in Console I assume
And.... it crashes after I remove the log line
Yes, try to find out why is parent == null ,that is why is ActivePannelTransform not returning you the parent.
I see, but a SetParent(null) can crash the Unity....
I should open a new project and test it
Sure
Try downgrading the unity version
and if so (issue is gone with the downgraded version), report it to Unity hub forums as others may encounter the same issue, should prioritize the potential fix
Anyway thx for the help
Hope it works out for you
what is the purpose of this code? to pool ui elements?
Hi there, we collaborate with a team that told us the following:
When rescaling in Unity, Unity has to do an operation every frame for every asset that is rescaled. On top of that, if the rescaling is non linear (Height is 0.6 and width is 0.8, for example), then unity has to do ANOTHER operation every frame. So, optimization-wise, since we'll be targeting mobile, it would be best to scale assets in maya.
I did not find any information concerning this performance optimization on the Unity documentation. Someone can confirm that (or not)?
I mean I guess it's technically correct but it's a matrix multiplication based on the transform values, it'll be executed either way afaik
mmm that makes sense ^^, thanks 🙂
that is true
in early days of my prototype I declared a scale const that was applied to every object in the game upon instantiation
when I found the scale I wanted I removed the scaling const and performance increased significantly
Thats mind blowing actually. Hmm. I wonder if this also dirties the object hierarchy. That would be a huge problem.
no idea about that, but when every object in the scene has a non-one scale it can reduce fps by 2 or 3 times, depending on the object count ofc
I presume this is not just a editor thing but also applies to builds?
personally, never tested in built versions, discovered it randomly and didn't occur to me to see how it works in a build
should be pretty easy to test
Ok 🙂 but how do you deal with scattering on environment in that case? You re-scale all your maya object and create different model for the same "rock" for example but with different size?
all my assets are programmer art, but for one of the experiments I had to bake maps at one scale and export the model at a much smaller scale
I'm not sure if that was the question, I'm have very little knowledge regarding asset workflow
I think he asked: how do you then create varied environments if you cannot for example randomize the scale of your trees 0.8-1.2 etc...
oh, I will have to research that myself at some point
I remember reading about render optimizations and one of them mentioned a more efficient way of applying random variations to some of the object properties, including scale
DrawMeshInstanced for example, uses standard 4x4 TRS matrices
and I already use it for some environment objects
but I never tested how a non-one scale in that call affects performance because everything has a scale of one
varying properties is one of the todo items for me
I do some benchmark with instantiate items with a scale of 1 and other with random scale and there is no different at all ... :/
Just tried myself and I can no longer reproduce it
I googled just to check what's the deal here and found a bunch of pages saying the same thing - scaling does affect performance. I guess it depends on the render pipeline and / or unity version.
I started my project in built-in, but transitioned to URP later
in built-in it gad a huge impact, now there's no impact at all
how do i detect how much a number variable is changing in a second on average from the past 10 seconds?
divide the total change over the last 10 seconds by 10
yeah, but how do i actively keep track of what the value was 10 seconds ago for every second and compare that?
you can use unirx to express this succinctly
you would still need to know the name of the thing you are talking about
unfortunately unirx does not implement Window.
the problem is that i want the value to be updated every second
Coroutine with loop in it
so every second it would detect what the value was 10 seconds ago and see what it is now
how do i store what it was 10 seconds ago all the time without making a huge spaghetti
Maybe a queue would be better here
doing it this way means the user has to operate a circular buffer, which imo is just as hard
you can't dodge the hard problem here
there are no shortcuts here
So, simple or overkill way?
there's no simple way. the simplest would be if unirx implemented Window
it doesn't. so you can implement window yourself using Scan, which is too much of a brain explosion
compared to doing it in a loop
i guess i could make a list of 10 values, then have it set to a value every second and loop back
the name of that datastructure is called a circular buffer, but that's only 1 part of the problem
there are 3 more - how to have something happen "every second", how to calculate the average (easy), and then how to emit the average "every second"
while (true)
{
queue.Enqueue(newValue);
var tenSecsAgo = queue.Dequeue();
yield return new WaitForSeconds(10);
}
There
here's an example of how i do it to average a value (in this case, a vehicle speed) over the last 360 frames (m_BufferSize)
what is "queue" referencing?
A Queue<T> instance
you can find an implementation of CircularBuffer online
Which is a collection that is FIFO (first in first out)
instead of Observable.FixedUpdate you have Observable.Interval(TimeSpan.FromSeconds(1))
the reason this method is good is that it solves two hard problems - how ot have something happen every second, or if that isn't good you can do something else, and how to emit the value "at the right time"
i don't know what to tell you, it's this hard
there are no shortcuts
you can of course implement all these things directly
- a circular buffer
- something that makes a measurement every second
- something that calculates the average
- something that "emits" the calculated average every second
you can do a circular buffer with a queue
you can do a measurement every second with a coroutine
you can calculate the average in a coroutine
yeah that makes sense, i thought of something pretty simple actually and i'm going to try that
you can emit the average... uh oh, that one is tricky. surely you want to know when the average changes, you don't want it to stairstep
hmm... not likely to be the right answer if it's "simple"
define "simple"
maybe say it here first
yep, but i feel like it might be good enough
basically i'm just making a list and having it cycle through and assign a value to each spot and loop it, then just see what the value was 10 spots ago
i mean gameplay wise
just a silly little idler :P
the problem is that my idler contains randomly spawned objects that have a bunch of randomness involved and they can be chosen to be collected/not collected, so no way to calculate it from just the spawns
what are you taking the average of?
the objective is to get the money value and see how much it increases every second
okay
just sounds like a simple MpS counter at first, but it's more complicated this time :P
well a moving average is a pretty typical thing to do, and has a very fixed meaning
i don't know if it's something that is often surfaced in idler games
the thing i wrote is indeed a moving average
with a window size (see, there's that word window again) of 360 (really m_BufferSize) frames
pretty much all idle games have this, but the vast majority have the income be a static value of income per second so that's very easy to calculate, they're not actually looking into the value and seeing how much it has changed
Observable.Interval(TimeSpan.FromSeconds(1f))
.Select(_ => GameController.instance.Money)
// this is a tuple
// scan means, do something every second, and hold onto some
// state (in this case, the buffer) that we can revisit later
.Scan((window: new CircularBuffer<float>(10 /*seconds*/), average: 0f), (state, value) => {
var (window, _) = state;
// circular buffer pushback means
// the oldest item gets popped off
// when the newest item is added and you are at capacity
window.PushBack(value);
// the average
// this is a tuple
// this measures the average in the buffer
return (window, window.Sum() / window.Size);
})
yeah i see, i understand pretty much none of it since i haven't dabbled in more complicated code, haven't ever needed to
so i'll try out my method first and see if i can get it to work
hmm
well i think you'll figure it out
@somber grotto well i annotated it for you so that it might make more sense
okie, i'll have a look in case my method doesn't work :)
New version
while (true)
{
_queue.Enqueue(newValue);
if (_queue.Count > 10)
_queue.Dequeue();
_average = _queue.Sum() / _queue.Count;
yield return new WaitForSeconds(1);
}
i haven't done anything with queues so not really
Think of a queue as a real queue of people
You add people at the end of the queue, and you pick people from the start of it
It's the same for C#, but it's for values instead of people
Enqueue adds a value at the end of the queue
Dequeue removes a value from its start, "sliding the other values forward"
oh that's exactly what i'm trying to emulate with a list instead 😄
this runs every second on what i have
but yeah imma try out what you wrote
cool it works for getting an average, now just need to do the other stuff :P
@fresh salmon how do i pull values from the queue? like with lists you do list[2]
nvm i just do .First() and .Last()
typically you should only be using Peek() and Dequeue()
oh i mean like, looking at the values
foreach or Peek()
first and last works, linq helps there
Indeed, First() might be slower than Peek() though
since those are the exact values i'm looking for
ah, okie
i'm not really concerned about speed since i'm running just one of these
@fresh salmon this ended up being my code, MoneyMade is basically just Money but it never gets subtracted from, this way when you buy upgrades the money per second counter doesn't go negative
Nice, thanks for the update!
Does anyone know what might be wrong with unity ads. I have made all the stuff work in the editor including all the buttons that trigger the adds but when I build it the initialization function does not work. Does anyone have any ideas on what could be causing it? Im pretty sure its nothing got to do with the code itself as the Advertisement.Initialize is a unity function and not written by me and that seems to be the point of failure.
Hello, I'm Efe Şantay, I'm From Turkey, And My Age İs 11. I'm Doing Trajectory Script, On Unity 5.3.2f1. And My Script Works Like That, İf Tennis Ball Game Object Was OnMouseDown, İt Does, Trajectory.SetActive(true). And İf OnMouseUp, Trajectory.SetActive(false). But My Trajectory Code Gets Error. Error Area This And Error Text: Assets/Scripts/Trajectory.cs(36,40): error CS1501: No overload for method Instantiate' takes 2' arguments. And You Can Look My Code Trajectory.
See? The dotsList [i] = Instantiate (dotPrefab, transform.position, transform.position, Quaternion.identity); İs, Gets Error. What Should I Do In The Correct Version Of This Code? Or, What Should I Choose The Corret Version Of Unity? Please, Help Me And Say The Error's Method For Me, Ok?
And You Can Look Error Pictures Too.
Message By Efe Şantay.
you need to add Quaternion.identity as a third paramater and a vector3 as a secound paramater
this is on a mobile device right? have you tried running with the debugger attached?
I get no errors at all I have done a noob thing because I could not figure out how to get the debugger to run on a build so I created a text element to to log the errors to but i didnt get any
hmm
are you using a macOS + iOS or windows + android device?
it's worth learning how to debug
widndows + android
real phone
interesting
is your phone weird?
did you get it with Weird from the factory?
is it rooted?
most likely
you have Unity Ads configured for debugging right?
meaning even when you deploy it to your phone
it should still be in a Debug / Devleopment account
not sure what they'd call it
no i disabled it for the build
you mean test mode right?
the same thing happens weather i have it on or not tho
are you sure
"Note: You must enable test mode before testing ads integration, to avoid getting flagged for fraud."
it should always be enabled
you should be running test mode until you are in the production lane in google play / released to the app store in ios app store
oof thanks for telling me that i was doing something very risky
im changing it right now
ok so im rebuilding it again with test mode enabled
Another interesting thing is that the void OnInitializationFaild does not fire either because i did put my logger in there and it did not show up
#854851968446365696 Configure IDE
So I'm trying to override the currently selected button in my UI, but the selected button in the event systems code either seems to be going slow or keeps updating the same button as selected. Is there any easy way to fix this or diagnose it? I'm using the publisher subscriber method to send all of my information, so I'm not sure if the timings are just somehow off or not. I've tried setting the selected button to null as well but it says it's busy when I do that.
The version of Unity I'm using is 2021.3.2f
by going slow do you mean the game is getting slower or the event is dellayed?
do you have any corutines in there?
No
does it slow down over time or is it slow as soon as you start?
So the event gets called but seems to be canceled out by the currently selected button.
If I click somewhere with my mouse it will deselect it, but it won't work through the code.
Because it says it's "already selecting an object"
Does anyone have any experience in mesh subtraction and blendshapes?
Trying to transfer a blendshape to a mesh with pieces subtracted
so its not a problem with events but with the button
- at runtiem
does it trigger at all
The button seems to trigger properly when pressed
so what is the scenario when it fails
It triggers the event to switch to another button, but it can't seem to switch buttons, as it is stuck on itself.
its like it does not deselect properly then
Seems so, but I can't figure out how to get it to deselect itself before trying to change the selected button.
Have you looked at the property Interactable in case that mighet get set to false
I've tried changing the settings on the button, and forcing it through code, but no luck so far.
there is an alternative way to make your own button component if that is not working for you.
Hmm
I can have a look for a link to an article on that its pretty straight forward
That would be great if I can't get this to work.
one sec ill have a look
Maybe the event system is going too slow for the events to trigger one after another, I'll try to convert it to a delayed coroutine real quick.
I cant find an artical sorry
but that is a good idea corutines do run on another thred
Coroutines do not run on another thread
The delay worked, so it seems the events didn't want to play nice even though they should have triggered one after the other.
nice
Hopefully no one notices a slightly slower inventory. 😅
Thanks for the info too, I'll have to look into it. 🙂
@halcyon schooner lol was just throwing down on UI deselection stuff today
such a pain
ended up yielding until EventSystem.alreadySelecting returned false, before trying to do anything. that worked on my end. https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.EventSystem.html
I have a world the size of 5kx5k, I have an image of the world at resolution 1920x1080 at the size of 600x600. I want to place a map marker on this UI map of 600x600 compared to the players position on the world in the 5kx5k area. Who knows how to do this?
You'd determine the bounds of your world and calculate the players position within them. Say they are at coordinates 1374, 4009 in a 5000x5000 world. So you would then translate that position into the 600x600 space. So multiply each coordinate by the fraction 600/5000. Which gives you a new, re-mapped position in the UI map space: 164.88, 481.08. At least, that's how I'd go about tackling this. Good luck.
Don't I have to scale this to the resolution too?
Possibly. I don't fully understand from your original message how the resolution is playing into this. But it seems like it'd pretty straightforward to test and find out. Hopefully.
Also, 164.88, 481.08 is getting set how? localPostion?
This depends on how your UI is structured but probably RectTransform.anchoredPosition.
Well like if a player changes screen resolution from 1920 x1080 to something like 900x600 I'd imagine this effects it
Ahh. I see. If you're using Screen Space - Overlay render mode, you don't need to worry about this (as much). You can probably use the Canvas.scaleFactor property.
Canvas.scaleFactor is a lifesaver.
Assuming your UI has its anchors and pivots set properly to scale along with the Canvas.
Oh and also need a CanvasScaler component on the same GameObject as your Canvas.
Set to scale with screen size
Thank you so much! I did the math right, screen is screen space, so i screwed up on the anchoredPosition, thanks!
Oh, awesome! np
When you're setting up in-app purchases using a ConfigurationBuilder, can you have multiple or do you need to just have one? Do you need to add every single product before initialising, or can you do it in stages?
I've got to procedurally generate and add a massive quantity of products (e.g. thousands across different categories) and I'm wondering how/if I should split them up
How would you avoid singleton while keeping your script modular?
Example
public class A : MonoBehaviour
{
static public A instance;
...
public System.Action<int i> onDoSomething;
void DoSomething(int x)
{
onDoSomething?.Invoke(x);
}
public void UpdateSomething(int y)
{
Debug.Log(y);
}
}
public class B : MonoBehaviour
{
A.instance.onDoSomething += (int x) => ModifySomething(x);
void ModifySomething(int x)
{
x += 1;
A.instance.UpdateSomething(x);
}
}
In this way, class A doesn't really care if class B exist or not.
But the use of that singleton worries me since I might unintentionally abuse it later in the future
Proly you never heard of factory pattern
at the same time, that may not what your game wants... without further context hard to tell
and the concept quite the opposite from one to another
What's your definition of "modular"?
Also what's the problem with a singleton?
Modular in a sense that class A doesnt need to know if another class (B) is even exist or not.
Currently I have no problem with a singleton, but considering that some people consider singleton as evil 😝 , I might want to try to avoid it... if possible...
That said, I found that it perfectly suits my intention
Factory pattern, iirc, needs to know class B first for it to be instantiated by the factory class (A), which seems to break the modularity
@somber tendon make sure to use singletons when you know there will only need to be one of it ever
Anyone here used the IAP package? Once you initiate a purchase, what would you use to actually initiate whatever the specific purchase does for you? Additionally, how do you ensure a user's purchases are kept between closing and reopening the app? I presume it's stored on a server somewhere? In that case how is it retrieved?
or is it better to write like this instead?
public class B : MonoBehaviour
{
A aInstance;
void Awake()
{
aInstance = FindObjectOfType(A);
aInstance.onDoSomething += (int x) => ModifySomething(x);
}
void ModifySomething(int x)
{
x += 1;
aInstance.UpdateSomething(x);
}
}
okay it seems I just use some custom code to determine what the user purchased based on the Product's id
this is just a slower singleton implementation
Yep, but at least it doesnt look like one 😜
there is nothing wrong with singletons
if each new bullet gonna FindObjectOfType your explosion spawner singleton then this will definitely hurt 
making one global facade with static access that handles a bunch of singleton components/services is the most cleanest in my opinion
How would you avoid singleton while keeping your script modular
the unity component system
for example, dependency injection
var bullet = Instantiate(bulletPrefab);
// during a match
bullet.gameManagerComponent = GameManagerComponent.instance;
// when looking at the bullet in the inventory screens
bullet.gameManagerComponent = HomeScreenGameManagerComponent.instance;
👐 people don't like it not because it's bad, but because it's too simple and they're really doing these cathedrals of engineering in order to procrastinate🌈
isnt dependency injection just a fancy word for assigning object references in a Unity context?
haha
But this make the class that instantiate the bullet needs a bullet class first, thus, make it less modular, it wont run if I dont have bullet class
I'm not using interface atm
assigning references as the object is created.
but yeah I think dependency injection is an over-fancy phrase for what the doctor is prescribing
though I've seen people use that phrase for it a lot
people are way too afraid of singletons tbf
Yeah, every time I heard of DI, I imagine it as an overly complex framework
unity sort of already does it with [RequireComponent(typeof(T))]
Well I'm used to dealing with "real" DI frameworks like Java's Guice or Spring
which could in theory just reference a singleton
that is its actual dependency injection framework
So yeah it seems a little milquetoast
[RequireComponent(typeof(T))]
class B : MonoBehaviour {}
interface IMySingleton {
int value { get; }
}
class MySingleton : MonoBehaviour {
// an actual singleton pattern
}
class T : MonoBehaviour, IMySingleton {
public int value => MySingleton.instance.value;
}
but why would anyone bother with this? it's very verbose
^that is dependency injection in a nutshell using just unity primitives
it just goes to show you don't need any of that stuff in a bare bones sense*, unity ships with it, because the component model is old
guice shudder
remember Dagger?
i'm a maniac though... i use vertx with quasar fibers
long ago, when "Project Loom" was just a star in ron pressler's eye, and you could still get venture funding for a java library...
yep when I was doing Android stuff like 6 years ago and Dalvik couldn't handle Guice for some reason
"yeah i member"
I didn't know about Project Loom until now
what is this, goroutines (yes, i.e. Golang) for Java?
oh god "Fibers"?
lol
so im wanting to write code that basically detects what website a project is downloaded from, and if its downloaded from anywhere besides the specified websites, it will initiate basically an anti piracy screen (even though its not a paid project, its just supposed to work as an anti reupload measure), i tried looking up a way to do this, but i didnt find anything, and was wondering if anyone here would know how to make something like that
Yes, It's a part of my ui pannel framework, based on UGUI
And .... it reappears after I rebooting the Unity Editor
Currently I have two of my colleagues working on this bug
And we found out another crash point
The code that marked purple produce the following crash log:
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at UnityEngine.GameObject:SetActive <0x00153>
at DEYU.AdpUISystem.Managers.AdpUIPannelManager:PrepareBufferedPannel <0x0050a>
at DEYU.AdpUISystem.Managers.AdpUIPannelManager:PrepareBufferedPannel <0x000ca>
at Common.UI.UniversalGameManager:OpenDialogMenu <0x001da>
at Common.TimelineExtestion.COM_ADialog_Play_Behaviour:OnBehaviourEnter <0x0018a>
at Common.TimelineExtestion.ExtendedPlayableBehaviour:OnBehaviourPlay <0x0013f>
at <Module>:runtime_invoke_void__this___Playable_FrameData <0x00259>
at <unknown> <0xffffffff>
at UnityEngine.Playables.PlayableDirector:Evaluate <0x00140>
at Common.TimelineExtestion.GameTimeManager:Update <0x002fa>
at System.Object:runtime_invoke_void__this__ <0x00187>
=================================================================
Received signal SIGSEGV
Obtained 57 stack frames
0x00007ff610e2f344 (Unity) UI::CanvasManager::AddCanvas
0x00007ff610e436d3 (Unity) UI::Canvas::AddToManager
0x00007ff610e43d05 (Unity) UI::Canvas::AwakeFromLoad
0x00007ff6108cfc27 (Unity) AwakeFromLoadQueue::InvokeAwakeFromLoad
0x00007ff6108cac43 (Unity) AwakeFromLoadQueue::AwakeFromLoadAllQueues
0x00007ff6101aca4a (Unity) GameObject::ActivateAwakeRecursively
0x00007ff6101b3fe9 (Unity) GameObject::SetSelfActive
0x00007ff60fa3d69b (Unity) GameObject_CUSTOM_SetActive
0x0000024f0706f1d4 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.GameObject:SetActive (UnityEngine.GameObject,bool)
Thats very odd error for sure. I suggest reporting the bug on unity.
Yep..... but for some reason I cannot upload the project to Unity End
And, the code that marked red produce the following crash log:
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at UnityEngine.Transform:SetParent <0x00156>
at UnityEngine.Transform:SetParent <0x00092>
at DEYU.AdpUISystem.Managers.AdpUIPannelManager:PrepareBufferedPannel <0x0028a>
at DEYU.AdpUISystem.Managers.AdpUIPannelManager:PrepareBufferedPannel <0x000ca>
at Common.UI.UniversalGameManager:OpenDialogMenu <0x001da>
at Common.TimelineExtestion.COM_ADialog_Play_Behaviour:OnBehaviourEnter <0x0018a>
at Common.TimelineExtestion.ExtendedPlayableBehaviour:OnBehaviourPlay <0x0013f>
at <Module>:runtime_invoke_void__this___Playable_FrameData <0x00259>
at <unknown> <0xffffffff>
at UnityEngine.Playables.PlayableDirector:Evaluate <0x00140>
at Common.TimelineExtestion.GameTimeManager:Update <0x002fa>
at System.Object:runtime_invoke_void__this__ <0x00187>
=================================================================
Received signal SIGSEGV
Obtained 54 stack frames
0x00007ff60bd7cbfd (Unity) UI::CanvasRenderer::UpdateParentHierarchyChange
0x00007ff60b56c01f (Unity) TransformHierarchyChangeDispatch::DispatchSelfAndAllChildren
0x00007ff60b564c0b (Unity) Transform::SetParent
0x00007ff60aa8a188 (Unity) Transform_CUSTOM_SetParent
0x000001c93ff62c37 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Transform:SetParent (UnityEngine.Transform,UnityEngine.Transform,bool)
You can report how to reproduce the bug. What is the version you using. What is happening when the bug occur, etc.
Hey everyone! I've created an ocean vertex displacement shader using shader graph, and now Im trying to reference the vertices on the mesh (with the shader material) to make a buoyancy script. However when I reference the vertices, the position of them is set to the default position, without accounting for the shader. Do shaders not modify the properties of the mesh itself, only visually change the object? Is there anyway around this?
Shader only visually change the object.
dang it
You need to run the algorithm in code to calculate the height at a point.
Is there anyway around that?
ok
So if you're doing gerstner wave calculations in shader, do the same ones with the same values in code at runtime to sample the position.
You don't, you run them in tandem.
I think you need to write the script for the node...
wouldnt it make sense to run the whole shader in code, that way I dont need to run multiple things that do the same thing at once?
Makes sense.
So unity has ways of accessing those functions in code?
The CPU side will only be running samples where it's needed because it's very expensive to run thousands to millions of operations on the CPU
ok
the GPU side can do that with ease, but it's extremely expensive to pass that data back to the CPU
You can't access nodes from code, no. They're just code themselves.
I've only used Mathf.Perlin noise in the past
So I have to rewrite the gradient noise function that shadergraph uses
and use the same seed
to find the height of the ocean vetex's
is that correct
Yes
or does unity have a built in gradient noise function
Though,more specifically, the height that is calculated at a specific position.
Nothing to do with vertices at this point.
true
Unity doesn't have a accesable gradient noise function that I can use?
I know very very little about how noise fucntions work
Trueee
I forgot about the shadergraph documentation lol
thanks for your help
this should be interesting....
Honestly, water is one of those things that it's just easier to get an asset for that also supports bouyancy.
Let someone who is a master shader dev solve it for you and get on with your project.
your right
but I'm poor
and I'm up for the challenge
and I've tried finding water shaders that I like, and work with what I'm making in the past, and its been hell
And I've gotten decently far along making the water so far and it looks good
cant give up now!
Thanks for your support tho guys, I really appreciate it
Unity doesn't make the shadergraph functions public right? So I have to copy and paste all of the code on the shader graph documentation and plug it all into each other?
Hey everyone, how do i create a complex combo attack system similar to platinum games in 2d. I have seen tutorial that writes code for playing three different animations in row after input x amount time, but i want to know how to play different animation according to different inputs like for eg pressing x 2 times and y 1 time etc
Are you planning on using Unitys animator
Yeah, i currently use my own script animation state controller. Dont want to deal with animator web fuckery
does anyone know how to access the functions used in the unity shadergraph documentation?
when I copy and paste this float unity_gradientNoise(float2 p) { float2 ip = floor(p); float2 fp = frac(p); float d00 = dot(unity_gradientNoise_dir(ip), fp); float d01 = dot(unity_gradientNoise_dir(ip + float2(0, 1)), fp - float2(0, 1)); float d10 = dot(unity_gradientNoise_dir(ip + float2(1, 0)), fp - float2(1, 0)); float d11 = dot(unity_gradientNoise_dir(ip + float2(1, 1)), fp - float2(1, 1)); fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10); return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x); } into my code
it gives me a whole lotta errors
I added the Unity.Mathmatics namspace, and it fixed some of it
but not all of them
That's written in HLSL, not C#
Shader language has an entirely different concept 🧐
ok
hello guys
i want to instantiate 4 objects in the same time randomly and in random position without any repetition
but i have a problem withe the instantiating timing
the 4 squares are spawning so fast and not lined under each other
Does parameter col in OnCollisionEnter(Collision col) give information about the surface it hit (whether it is triangle, cube etc.), something that could help me manually calculate surface normal in any way. As one could imagine, Unity docs are very descriptive.
so i assume normal of the contact point is not what you are after?
Contact point normal turns out not to be a surface normal but a normal of the collision, which depends on the angle of the impact.
However, based on collision I could maybe get data about what polygon it hit and its vertices.
That would be helpful for calculating my own surface normal (actual normal)
so you would need the surface normal at the nearest point the the impact on the mesh
(keep in mind that collision and visible mesh might not be the same)
Correct, something like this.
It doesnt have to be 100% accurate, error of =0.1% or in range of that would be acceptable
I am aware that sometimes it might select a neighbouring polygon with this approach but the angle difference isnt too big since the dome (object that a player hits from within) is huge.
my best guess is to transfrorm the collision point in the space relative to the mesh you want to search over
then find the closes vertex and use the normal of that vextex index
(doing some testing with that)
I should point out that it is a concave mesh.
You are in the dome
Shooting the walls of the dome from within
Its not convex relative to you
do you want the normal of the collision mesh or the visible mesh?
Actual mesh, but I would expect them to be the same or am I wrong
Ill sketch, one second
A convex mesh collider can only have 255 triangles so it might not match your rendered mesh
Hmm that actually be
Ill check
This is what I am looking for essentialy, an object (capsule) hitting the triangle and getting surface normal of the surface where collision occurred. Red dot is contact point.
I also make it stuck there, so kinematic = true. Could that affect, probably not?
I made a small test script that gets the nearest point to a game objects position and gets the normal for that point
using System;
using System.Linq;
using UnityEngine;
public class FindColosestPoint : MonoBehaviour
{
public MeshFilter Filter;
// Update is called once per frame
void Update()
{
Vector3 myPos = Filter.transform.InverseTransformPoint(transform.position);
var lowestValObj = Filter.mesh.vertices
.Select(x => new { MyObj = x, Value = Vector3.Distance(x,myPos) })
.OrderBy(x => x.Value)
.First();
Vector3 foundPos = lowestValObj.MyObj;
int index = Array.IndexOf(Filter.mesh.vertices, foundPos);
Vector3 normal = Filter.mesh.normals[index];
Vector3 foundPosWorld = Filter.transform.TransformPoint(foundPos);
Debug.DrawLine(transform.position,foundPosWorld);
Debug.DrawRay(foundPosWorld,normal,Color.green);
}
}
it should be easy to adapt that to use the collision point instad
Wow thats awesome👌 thank you, will check it in a bit (currently at the restaurant)
Good eating 🙂
does the contact point normal really depend on the angle of impact? in a local sense a collision happens between two points (really, one point shared by two surfaces), any velocity should be irrelevant, and indeed the 2 points should provide a normal to the surface as that is largely what a collision is
In my case it seems as if it does depend. Different angles of projectile (capsule) colliding with the surface is causing different normals. I hopped to conclusion that apparently angle of impact affects the normal, however as you pointed out, it does not make sense.
I wonder if it's an issue with fast moving projectiles & interpolation
That could also be. I am so intrigued to test out the code above but I am the restaurant now...and most likely wont be back to Oculus to try it out until later this evening 😢. Thanks for all suggestions tho!
Hi, İm Errored On ProjectileDragging Code At (45,72) Area, And Code On İn The First Picture Or İn 2022-08-10(1).png.
And Here's Pictures And My Code:
Velocity is a Vector3
can i check the code version?
I dont understand your question
i said the coding Of Velocity is a Vector3, in like This example:
tennisBallPrefab.GetComponent<Rigidbody2D>().velocity = dir * 8; // 8 is multiplier to our force.
oh, let me try, it does or doesn't works, İ Back To You Again.
İ think İt's Worked, And Here's Updated Version Of My Code:
tennisBallPrefab.GetComponent<Rigidbody2D>().velocity = prevVelocity * 8; // 8 is multiplier to our force.
İt's Like That? İf Yes, Ok. İf No, Ok, Let me try Other Version.
That's OK
as long as prevVelocity is a Vector2
ok.
And İm Created New private Vector2 dir; And İm Tried To tennisBallPrefab.GetComponent<Rigidbody2D>().velocity = prevVelocity * 8; // 8 is multiplier to our force. Code, İt Work's Again.
private IResult ThereIsNoMultipleIntegrationManager(string orgNumber)
{
_orgAdminUserService.GetAllByOrgId(orgNumber, "", true, true);
}
``` Is there any way of sending the true and false values at the same time
so it will query both "false" and "true"
Do you mean you want one parameter to be both true and false at the same time?
@upbeat path, İ Have A Error Question On You, (55,50) And (56,33) İt's Gets 3 Errors, 3 Errors Code İs: CS0119, CS1502 And CS1503. Here's My Code And Pictures:
The error messages are telling exactly what is wrong and where it is wrong, you need to learn to debug this basic stuff yourself
Not to gatekeep or anything but I feel like this is more appropriate for #💻┃code-beginner
Absolutely
and he should not have pinged me
ok.
Does anyone here have much experience with MoonSharp for Lua?
function Spin(transform, speed)
transform.rotation = transform.rotation * Quaternion.angleAxis(speed * Time.deltaTime, Vector3.up);
return transform
end
UserData.RegisterType<Transform>();
UserData.RegisterType<Transform>();
UserData.RegisterType<Vector3>();
UserData.RegisterType<GameObject>();
UserData.RegisterType<Quaternion>();
UserData.RegisterType<Time>();
DynValue t = ModLoader.Instance.RunModScript("spin.lua", "Spin", new DynValue[]{UserData.Create(this.transform), DynValue.NewNumber(2)});
getting
attempt to index a nil value
I'm under the impression that registering the type is all I need to do for it to contain all it's member data and functions, but because LUA I'm also not sure on which indexer it's failing 😅
It could be any one of those. If you have debug information about which line it is, you could split it into multiple lines to find the culprit:
function Spin(transform, speed)
local up = Vector3.up;
local deltaTime = Time.deltaTime;
local angleAxis = Quaternion.angleAxis(speed * deltaTime, up);
local rotation = transform.rotation;
rotation = rotation * angleAxis;
transform.rotation = rotation;
return transform
end
Thanks, that's not a bad shout. Just hope it gives me line number errors instead of bytecode indexes
I assume you are using some capitalization conversion in MoonSharp to use Quaternion.angleAxis instead of Quaternion.AngleAxis?
Yeah, everything gets changed to camelCase in MoonSharp
Thanks for the help, managed to fix it. It needed the Vector3, Time, Quaternion classes etc. passed to it explicitly
Hi...I am looking for a way to run a Standalone Linux build of my Unity app in a Docker container on Ubuntu 20.04
I found the GameCI containers but not sure how to deploy my app in it.
Any pointers for the same would be much appreciated!
what's your objective?
@undone coral CI/CD essentially. So, start with deploying the Standalone build in a Docker container, run unit and integration tests in Docker and then push to a production container.
push to a production container?
is this a server backend?
how does it fit into your game i mean
Sorry, I meant push to production build. No server, its all local
Its a desktop application
Completely self-contained.
Linux only
okay
that's interesting
lol
are you streaming this?
are you trying to do some kind of streaming?
yes
okay
do you only need an artisanal quantity of streaming?
like an artisanal number of concurrent users, perhaps for the purposes of a demo
that usually means 1
Yes
okay
exactly, just 1 user
do you want to stream from a container?
meaning do you want unity standalone to be running inside the container and streaming the video?
I would be okay to have Unity installed on the Host and simply run the application inside the container
Unity meaning the editor? i mean the built player
Oh yes, the built player should run in the container and stream from within the container
is your goal to stream the rendered visualization from the standalone built player from a container?
okay
have you seen https://player.appmana.com/watch/spacetable or http://player.appmana.com/bonneville ?
do you know what this is?
i think this is unity streaming with instant building from a git / plastic repo and i believe it's currently free
if you contact via https://appmana.com/waitlist
Stream apps and games directly to your browser. Join the waitlist.
and it seems to work on mobile too
@open yoke is this helpful?
Thanks, but not really. I'm looking for a DIY toolchain. Not a web-based solution/product
i see
well i think you'll do a little bit more research on this, what you're describing takes years to develop
how do you plan to do the streaming?
have you successfully streamed from a container?
No
it's okay if the answer is no
have you successfully streamed from a plain ubuntu bare metal box?
i hope this is helpful, i'm just trying to gauge where you are in this journey
have you successfully built a standalone player on a bare metal ubuntu box? was it an empty project or a project that contained your assets?
Yes I have
okay that's good
It was my project
do you want to add the streaming or has it already worked on bare metal ubuntu?
it's okay to be a little grumpy
i think this looks easy and it's actually stupendously hard
Streaming has worked before on the standalone build
on bare metal you mean
Yes
which package did you use?
For streaming?
yes
Its custom
can you talk about that some more
you'll see that i've been very candid with people about all the approaches in previous chats, for people who have wanted to do this
so i don't mean to make this feel like an interrogation, i'm sorry
are you streaming to a browser?
I'm trying to budget my memory better .... does anyone know what the memory cost of a material instance is in Unity ?
@open yoke anyway i'm available to be a resource here, i think if you want an artisanal quantity of users (one user) you should not do CI/CD and you should not try to build into a container. it's important to be candid with your actual use case
No I am streaming locally from outside. I use a custom GStreamer pipeline that uses shared memory copy to a Unity texture\
cool - do you mean you copy FROM a unity texture TO gstreamer?
or FROM gstreamer TO a unity texture?
so you want to stream video INTO a unity texture for rendering inside unity?
my spaceship is jittering. Spaceship rb is interpolate. Here is the code: https://gdl.space/cekuruzaxa.cs
I figured out that line 54 is causing it.
https://gyazo.com/044c0a364c21ba58c5d2f98d149fbbb9
it's negligible
people avoid creating material instances because of their impact on rendering duration not memory
is this a cinemachine camera?
yes
did you set it to FixedUpdate?
turn off interpolation and set the cinemachine camera to fixedupdate
and set your fixedupdate interval in your physical settings to 1/60
its object jittering. i tried it with typical camera. object was jittery
Just going to hide the issue for yourself
that's true but sometimes that's suitable for a prototype 😦
i am honestly not sure why the default isn't 1/60
it might as well be
i think you have to have to add torque (angular forces) for it to interpolate correctly. honestly i'm not sure why moverotation would gltich
i believe you that it does
torque is uncontrollate
yeah
Being slightly below a common monitor refresh rate is probably good so people find out about these issues
IIRC these smoothing methods just don't work very well with objects that are constantly changing their speed
it's easier if you are streaming some other audio/video source INTO unity
it's okay if you don't want to talk about this though @open yoke ... i probably know a lot more about this than anyone else you've talked to
does it have to be non-kinematic?
what's the gameplay purpose of that?
@open yoke i'll just caution that the game-ci docker containers don't really successfully build most complex projects, especially on linux
they are used mainly in github actions which are VM runners
you can use github actions with your own runner if that's what you want
do movePosition and moveRotation work with kinematic object?
Might work better if you do this effect manually based on input or something
guys how can i check object like OnTriggerEnter?
honestly i don't know 😦 i don't really build character controllers with rigidbodies
i would use an asset for this stuff since it's so idiosyncratic
Isnt the Unity Render Streaming package supposed to handle this sort of use case ?
yes
i tried rotating spaceship without moving and seems like mixing addForce and moveRotation causes jitter
but as you can see, the user wants to do like, the whole rest of the problem... streaming an artisanal 1 user isn't that challenging
i think people put themselves into an absolute colossal amount of jeopardy doing a demo for someone showing streaming of 1 user
and assuming this stuff can scale
i also set rb to isKinematic
thanks
now its not doing jittery stuff
yeah but it's also not really doing physics now 😦
i think moverotation may not consider the "incomplete" physics you have with the add forces
i'm nto sure
there's a way to do this
you can try freeze rigidbody rotation and rotate the gameobject instead of the rigidbody
or you may have to use AddTorque instead of setrotation
but then what really happens is people who write C++ plugins get grumpy
i can probably lerp speed when moving position to get acceleration
Setting the rotation will likely break interpolation. Afaik the result is the same with AddTorque
is there a way to delink particles from their attached transform?
do you mean shuriken particles or vfx graph particles
you can simulate shuriken into world space
and use a parent constraint to control its transform settings
well its not, but yeah I want the particles to move non-relative to their parent
it's not which?
is it shuriken or vfx graph?
so if the parent suddenly moves, the particles stay on their path and don't follow the parent
unity's particle system?
that's shuriken yeah
didn't know it's called shuriken
i think you can use parent constraints carefully
how?
okay well the betetr question is what's the effect?
ngl I am not that well versed in the particle system
just traditional particles emitted from a transform
i guess i'm not sure
gimme a second
I want it so when I move the object the particles don't follow
i don't want this
try world space simulation
it's a checkbox
Have you tried the render streaming package ? I havent but it does work with a build player right ? The rest would be handling spining up all the virtuals to scale
the render streaming package is okay
the underlying streaming approach is flawed in some ways but not insurmountable ones and the developer on it is trying to fix that
We have a metaverse client and I keep trying to explain that tje scales they want wont work on webgl so Im looking into solutioms
The rest would be handling spining up all the virtuals to scale
i think people underestimate this challenge not by 10% or even 100%, but by 1000%
I dont underestimate it at all
i think you should try the https://appmana.com/waitlist and see what happens
Thats why I plan to pay a platform to do it if and when we need it
it is free right now afaik
I saw that link yes will check it out as well
the reason i know it's free is because i develop it lol
i know a lot about this stuff
two guys here were trying to use agora and were in a great deal of jeopardy
you can see that i've contributed to com.unity.webrtc, the underlying streaming approach from the unity renderstreaming package
Thats cool. How would the platform handle a multiplayer situation ? Would the server run on your side as well ?
you can engineer it both ways - as a traditional networked multiplayer game or as a local multiplayer game that streams different cameras to different players
some guys are experimenting with the later and are quite happy
if it's traditional networked multiplayer, that server can run anywhere
i think there are certain concerns, especially for a global game, that make that complicated
you would probably deploy the backend side-by-side with the player instances, we run our own hardware in the US
but it's very painless to try. you connect your git or plastic repo, add our plugin as a unity package, and it'll be built and deployed
no pressure though
Can the tech be used in a established cloud ?
i think if you try to do this yourself, you're going to figure out everything except how to get it to run efficiently, that is what i focus on
yes it's run in AWS
Ok cool. Well I'll def tell the relevant dev team to check it out
Hey...sorry for the delayed reply. I was pulled into something else.
Yes I am streaming video INTO a Unity texture from Gstreamer.
why would this be in a container?
what's the objective? is there on screen output?
i can be really helpful but you gotta give me the big picture here of what you're actually doing
can anyone good with photon help me with getting a function to go off for master client? i have a maze type thing made by photon.instantiate and now im trying to destroy it all when game wins and make new maze
it works if master wins but if anyone else does it throws errors
my rpc wont work
{
PhotonView pv = this.gameObject.GetComponent<PhotonView>();
//GameObject.Find("ThreeOfClubs").GetComponent<CreateThreeOfClubs>().DestroyGame();
pv.RPC("MasterDestroy", RpcTarget.MasterClient)); //player1 = PhotonView.Find(1001).gameObject;
}
void MasterDestroy()
{
if (!PhotonNetwork.IsMasterClient)
{
throw new InvalidOperationException($"Only master can perform this action");
}
DestroyGame();
}
public void DestroyGame()
{
GameObject[] walls;
walls = GameObject.FindGameObjectsWithTag("Wall");
foreach (GameObject wall in walls)
{
Destroy(wall);
}
Destroy(GameObject.Find("Win(Clone)"));
}```
#archived-networking might be the best place
Not sure if that's the right place to ask but it seems advanced
I'm not sure how anyone can help me but perhaps there are some smart people here.
I'm developing in unity.
I'm currently trying to make a clothing system where I can swap meshes(clothing) at runtime. This itself is not that hard I imagine but it gets a bit more complex now.
Imagine an inventory where you see your player character full body with the working clothing system, so far so good.
But in my game you actually play in first person, as it's a shooter.
This means I only have the player arms & weapon in first person.
what's the problem? how the fuck would I attach the clothing from the full body mesh to the fps arms, so when you wear a white t-shirt it would be visible on the arms.
perhaps this is important : The fps arms are taken from the player full body, so they have the same bone structure if that's important
is that even possible?
one way to 'fix' that problem would be that everytime players create a clothing item, they also have to make a second version just for the fps arms, if that's visible in first person.
yes, every item has to be arted for both the POV and exterior views
Same goes for animations
What looks good in 3rd person usually looks bad in 1st person
arted? Does that mean every clothing piece needs to be done twice for fps and full body?
Yeah they would be seperated.
yes
Ah sad to hear. Thought it’s somehow possible to extract it from the full body and make it work somehow
Thanks a lot
i am trying to create my own city building game (like cities skylines), and i am thinking of ways how to save terrain data, is there a way to store it in .png files each pixel is point in my grid and height is represented in 24bit integer (0 - lowest possible point, 2^24 highest possible point)
you are at the start of a very long journey
i know
you can modify at runtime, save and load the terrain height and splatmaps
yes
you can get a texture2d as png bytes using built in unity functions
EXR might be a better choice. depends what you're going to do with the images
grid and height is represented in 24bit integer
this would be an R24 format, which doesn't exist in unity
it is simpler to use RHalf or RFloat
i was thinking of saving it in RGB24
ok
This isn’t a place you want to innovate is it
I mean the image format
It’s a long journey
is there a more performant way for a newly instantiated object to find my GameManager object in the scene than to call FindObjectOfType?
because it can lag a lot when each newly instantiated object has to look through a ton of others just to find the GameManager
Save it on a variable at start method. Then access that variable on your other script.
yeah thats what i meant by call FindObjectOfType, i might have tens of thousands of objects at a time and even one search can seriously drop frames
usually GameManager and similar classes are singletons, there is only one instance of them can exist (its your responsibility to enforce this though), and they have a static field referencing themselves, and other script access them through that static field
Is there a way for me to change a value of a variable that's local to a function from the onClick() event? Like is there a way for me to write something like "gameObject.GetComponent<Button>().onClick.AddListener(myFunction.value = 2)" or something?
I heard of a way that included delegating that function and creating a marker but it won't let me set the marker to an actual int or str...
What's stopping you from changing a variable in a class, and then read it from inside the function?
The thing is, I first need to change the variable of a function once the button is clicked because the buttons are generated at runtime, which first of all is why I need to access the onClick() via code, and each button has a value that I want it to display once I click it and if I click the next one, then the next value should be displayed so I'm kind of confused on how I should add this to the onClick().
You can add a function to onclick, that will take the text component and the desired value as parameters, and then assign the desired value to the text component inside it
I dont think changing a variable local to a function is something that makes sense in your scenario
the displaying text was just an example but in other words i just need to generate a value once a button is clicked
but the value that I need is calculated by the function that generates the buttons and i cant just call that whole function at onClick() which is why i needed it to change a local value at onClick() instead.
so i was hoping there was a method to store a value along with the generated button that can be fed back to a function on the onClick() event.
Try button.OnClick.AddListener(() => MyFunction( somevalue, someothervalue, anythingyouwant));
MyFunction will be called with those parameters on click
alright let me try
how would i create this static field?
yeah that still won't work because the parameter I pass is actually a mini algorithm so it needs to be under the conditions of the other function to work properly, otherwise if its ran casually it returns a random value.
?
what is your objective
well you gotta put it in another function, no other way
either pass the result or implement it in the other function somehow
var myvar = 0;
gameObject1.GetComponent<Button>().onClick.AddListener(() => {
// this works
myvar += 1;
});
gameObject2.GetComponent<Button>().onClick.AddListener(() => {
// this still works
myvar += 2;
});
it's the same value between the two functions
do you need the value be changed after clicking each button?
so that the first button would display 1, next one 3 etc
if yes, you need to make a variable outside of the function
and pass in just the 1, 2 etc
and modify the variable in the other function
so I have a nested for loop in a function that generates buttons, and I have a mini algorithm that tags those buttons. I also want the buttons to return the value they are tagged with when they are clicked, but that value is calculated once, and its when the button is generated.
a nested for loop in a function that generates buttons
are you trying to say you are experiencing a problem using your indexiin a lambda?
no clue what you just said lmao
alright ill post snippets
You can assign a new local variable to i then return that new variable on the button.
Why dont you do
var myvar = 0
button.onclick.addlistener ({MyFunction(myvar)});
myvar += 1;
button.onclick.addlistener({MyFunction(myvar)});
etc etc
as long as myvar isnt a reference it'll work
we'll see what the code is
we're about to find out
what this mystery question
is really getting at
lol
my bet is it's an index in a listener problem
just post the whole function code
Yeah im kinda confused what hes trying to do.
spawnedTile.name = $"{chars_index[focal_sector[focal_sector_indexer] + sub_val]}";
spawnedTile.GetComponent<Button>().onClick.AddListener(() => InputParser($"{chars_index[focal_sector[focal_sector_indexer] + sub_val]}"));
ABOVE IS THE THING TO TAG THE BUTTONS
formats gone off lmao
hmm
there's no for loop in here
show us the whole loop
it's looking EXTREMELY likely though
{
for (int x = 0; x < width; x++) //Loops over width
{
for (int y = 0; y < height; y++) //Loops over height
{
var spawnedTile = Instantiate(button,new Vector3(x * 290 + spawnOffsetX,y * 230 + spawnOffsetY), Quaternion.identity);
spawnedTile.transform.SetParent(GenController.transform);
if (n == 4)
{
focal_sector_indexer++;
}
if (n == 8)
{
focal_sector_indexer++;
}
focal_sector_indexer = Mathf.Clamp(focal_sector_indexer,0,2);
(spawnedTile.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>()).text = $"{chars_index[focal_sector[focal_sector_indexer] + sub_val]}";
spawnedTile.name = $"{chars_index[focal_sector[focal_sector_indexer] + sub_val]}";
spawnedTile.GetComponent<Button>().onClick.AddListener(() => InputParser($"{chars_index[focal_sector[focal_sector_indexer] + sub_val]}"));
sub_val -= 3;
if (sub_val < -9)
{
sub_val = 0;
}
(spawnedTile.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>()).fontSize = 200;
n++;
}
}
}```
oh that part can be deleted
all you have to do @short atlas
no need for that
well
i mean that clearly makes a huge difference
but okay
here's all you have to do
nah cause it never reaches outside the boundary
but this loop just generated the buttons
and it tags them accordingly
but i want to make the value they are tagged with the return value of the onCLick()
var finalSubVal = sub_val;
var finalFocalSectorIndexer = focal_sector_indexer;
spawnedTile
.GetComponent<Button>()
.onClick.AddListener(() => InputParser($"{chars_index[focal_sector[finalFocalSectorIndexer] + finalSubVal]}"));
i think it's going to be incomprehensible to you
to use the technical words
for what we are doing here
but all you have to know is, if you want the value of something like "focal_sector_indexer" at the "same time" as when you create your listener "function", you have to copy that value to a new variable.
okay? does that make sense?
problem solved
you just don't know about this problem
you're like the third person in the last 24 hours to have it
yeah this is slightly confusing
its cause i dont see why i need a final sub val when thats just a value to help calculate a certain position in a chars_index
cause its not the loop that doesnt work
i know, i mean i fixed your problem
okok ill try
but you don't yet comprehend why
part of it is you write code like a crazy man
part of it is that you're not really aware of what the code means
lmao people say that always

i remember using it in java
inline function or smthn
it is in java
no it's a lambda
it's not an inline function
but close enough
when you declare a lambda you have curly braces right?
that's a scope
yeah
look at the variables you're referencing, are they declared inside the scope of the lambda?
no.
not in your original code
ah
lmao i didnt even think you could do this in c#
every lambda looks at the same name and reads the same value
it doesn't get copied over
you need a new name for a new value
that's why we're doing var there
because the code inside your lambda hasn't executed yet
you should notice that too
so it's not like it "copies" just because you wrote the code (that's impossible)
anyway i was right
this was your issue
ok let me see if it works
i mean
i don't know if it's going to work
because i can't make heads or tails of what this for loop is supposed to do
incidentally if you had just done
var input = $"{chars_index[focal_sector[finalFocalSectorIndexer] + finalSubVal]}";
spawnedTile
.GetComponent<Button>()
.onClick.AddListener(() => InputParser(input));
you would have accidentally correctly dealt with the lambda closure pass-by-reference issue
damn ill look into all this more now that you mentioned it
i don't know if chars_index changes over time though
i have NO IDEA what's going on in this code
lol
okay so problem solved
but do you understand
damn if you dont mind could you explain it again? i'd like to understand the lambda pass.
lmao
it's okay
when you do
for (var i = 0; i < 10; i++) {
var button = Instantiate(buttonPrefab);
button.AddListener(() => {
Debug.Log(i);
});
}
every button will log "10"
because there's only one variable i, and they're all referencing the same variable i
when you declare the lambda () => {...} it DOES NOT copy the value of i in some snapshot of time
it just says, "where is the name i?"
"what is the value of the name i"?
does that make sense?
once you exit the for loop, i == 10
so when you click the button, you run Debug.Log(i), and it's 10
yeah, thats what i was trying to say 😂 that it wasnt capturing it from a snapshot in time but rather calling it on the onClicked()
it doesn't matter that at the moment you created the lambda, the value of i was 1 or 3 or whatever
yes
so to deal with this, because this is almost always what you want:
for (var i = 0; i < 10; i++) {
var button = Instantiate(buttonPrefab);
var finalI = i;
button.AddListener(() => {
Debug.Log(finalI);
});
}
bUt tHe nAmE finalI iS tHe sAmE
well, it is declared anew every execution of the for loop
so you clone 'i' in that moment in time and leave that clone unaffected
bro this is making so much sense
so there are 10 finalIs, one belonging to each lambda
with a copy of the value
okay great
it's called final because this is an error in java, and you fix it by declaring an "effectively final" or "final" variable
lol
i just met a messiah
guys any way to check this gameObject is raycasted or not?
Did you cast a ray and hit it?
👋 Hello, I opened a project that I haven't worked on in a while and it looks like the .meta file for a dll was filled with null bytes
The .meta file Assets/Core/TankCore.dll.meta does not have a valid GUID and its corresponding Asset file will be ignored. If this file is not malformed, please add a GUID, or delete the .meta file and it will be recreated correctly```
Screenshot from VSCode
Unity went into Safe Mode, but how can I get the guid of the file through the asset database, because I cannot do much when the editor is in safe mode (Edit: Editor scripts also do not work, any other way to access the asset database to get the guid?)
If it's just full of null bytes there's nothing you can do apart from deleting the file and letting Unity remake it
and hoping nothing was explicitly referencing it via GUID
@slender stag
It contains monobehaviours that is in my scenes
So idk if deleting it will unassign (or make them missing)
I have no idea, but if you are using source control surely you can revert it
I mean, if I had source control, I wouldn't be asking for help lmao (I wish I used it though)
Is there a way to browse the AssetDatabase directly?
Unity uses the GUID in the dll's meta file to resolve the scripts. (and uses the file ids it generates from the full names of the classes in it)
You're going to have to find where you've used a script in your game and look at the file (be it a prefab, scene, or scriptable object file) to find the GUID that it's trying to reference
You're then going to have to delete that broken meta file, and get Unity to generate a new one.
Then you're going to have to close Unity, and replace the GUID it generated with the one you found.
You're going to have to do manually through text. I do small modifications with Rider fairly often with its find and replace as it's fast as hell for that sort of thing.
You should really start using source control, because reverting a single file change certainly is easier than going through this rigmarole 😛
Found common guid: b01367d0e380e624084e66cbfccc2546
And yes ima add it to the repo lol (This was a side project, decided it was not necessary to add to the git repo... till now lol)
🤞
Status: Done!
It works!!!
Anyone know what is SRPBatcher.Flush and what does it do? This is running GLES3.2 on Oculus Quest 2
it seems to be connected to the reflection probe settings on the mesh renderers. With off I'm not seeing it
how can i get count of non-persistent UnityEvent listeners?
Don’t cross post ☹️
it's been like 10 min already
and there is huge ongoing topic already
have you checked the docs? bet you're not!..
read my question again
bet you didint read it
oh haha 🤣
either way, easy to tackle, no?
Make a List.. each time you add the Listener, add it to the list as well
or just an int as a counter, that would do the trick too
I've got a base class from which many other classes derive from:
yes
But when I create an instance of the class, the lists are empty:
allFurniture.Add(new Furniture("chair", "Chair", new string[] { "wood", "basic", "brown", "cheap", "rustic" }, new string[] { "sit" }, null, null, null));
Everything else gets set correctly. My first aproach was to ask for the lists directly on the base class constructor and assign them plus any derived class could add additional entries to the lists in their own constructor, but it didn't work
You have an issue in the constructor of Item. You loop over the actions and add them to the tag list (2nd foreach)
Just noticed, thanks
But that doesn't solve the issue
They both are empty at the end
And I am definetly adding entries in, at least, one
Place a breakpoint on the constructors, and step through
I don't see anything wrong with the code rn
Yup there is nothing wrong with the code, however, there is definetly something wrong with me xD
Found it, human error
I almost never debug through breakpoints because of the hustle of setting it up, but that was the way to go for sure. Thanks!
Texture2DArray textureArray = new Texture2DArray(textures[0].width, textures[0].height, textures.Length, TextureFormat.ETC2_RGB, true);
for (int i = 0; i < textures.Length; i++)
{
for (int j = 0; j < textures[i].mipmapCount; j++)
{
var mipData = textures[i].GetPixelData<byte>(j);
textureArray.SetPixelData(mipData, j, i);
}
}
textureArray.Apply(false);
``` Any idea why this adds a full white alpha to each slice in the texture array even when the source textures have no alpha ?
actually something fucky is going on. enve if I set every element of mipdata to 0
the alpha is there in the editor
the displayed size does not shrink as well
but if I open up the asset, its all 0
not a single 255 or f
i will away waiting for you 👍
