#archived-code-general
1 messages ยท Page 21 of 1
I want to ensure that I am instantiating my gameObject with enough space around it, such that when it rotates around (2D space), it won't clip with anything. I thought bounds would be the solve, but as I rotate, the bounds (understandably) updates. Any tips on a programmatic way I can find the maximum possible value of a bounds extents? Ideally something I could determine in editor, rather than runtime.
You can't. Best example of what you need to do is https://learn.microsoft.com/en-us/dotnet/api/system.action-1?view=net-7.0. See how they create a definition for each parameters number.
I read wrongly srry.
For this to work appropriately, I need to know the radius I want to search within, which my current thinking leads me to the extents of the collider (forgot some important context: it's an EdgeCollider). The collider shape is non-uniform so its extents change as it rotates on its Z axis, so I can't easily find the radius of which to put into such a function
use the longest corner / vert point
Ah, thanks. Browsing the Scripting API no built in method for this stands out so I suspect this would be a custom method parsing each point for the furthers from center - is that your understanding also or is there another approach?
if you wanna do it programmatically sure, you can also manually check in the inspector with gizmos and whatnot
get roughly the right radius from center
you can also get array of points in the Collider since it's a edge collider , find your radius by getting your largest distance from 1 collider point to another, I think
All of those suggestions seem valid, I'll give it some thought and dive in, thanks Null!
public class NoteScript : MonoBehaviour
{
public GameObject noteText;
private bool isReading;
private void Update()
{
if (Input.GetKeyDown(KeyCode.E) && noteText.activeInHierarchy==false)
{
noteText.SetActive(true);
isReading = true;
}
if (isReading && Input.GetKeyDown(KeyCode.E))
{
noteText.SetActive(false);
isReading = false;
}
}
}
is this note system realiable
what would the general technique be to press and hold a ui button in unity and have it execute a function every x milliseconds
because onclick requires press and release so thats no good
What do you mean by "reliable"?
Maybe use the IPointerDown/UpHandler interfaces?
is that still used if using the new input system?
Is UI affected by the input system?
i assume so
Hmmm... I don't know about it. Haven't used it yet, so not sure.
ill play around with it and see
But I don't think it is. These are event system events, so they're probably independent from the input system.
Hey, im making a chess game. I am trying to move the peice i am currently dragging to mouse Position. When using transform.position, it breaks my movement logic. What should i do? My code is attached
(This is for school btw thats why there is so many comments)
what do you mean by "breaks my movement logic"? what happens?
When i do it the reference of the previous sqaure my peice was on is dropped so i cant move my peice back to that square
@mental rover
Here is a video
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
currentlyDragging.transform.position = mousePos;
}
That code
it looks like you're doing some strange casting between Vector2's and Vector2Int's, storing board positions as Vector2's?
Im storing them in dictionaries
you might well be running into rounding and float comparison issues there
hmm
should i change everything to int?
Since i dont really use float bar the mouse Pos
_ExactPeices[new Vector2(previousPosition.x, previousPosition.y)] = null;?
mabye i can drop the reference of the previous pos
I'd try to approach it as having two layers, a data layer and a visual layer - the data of the pieces/board should be described with strictly ints, or Vector2Int if you prefer
the visual should use the data where appropriate, but has some freedom with where you have the visual gameobjects
in the case of an invalid move, you can refer to the data for where the piece should've been, and just discard the temporary visual
private void Update()
{
SwitchingLevel();
pressed();
}
void NextStage()
{
stageSelect = 2;
}
void SwitchingLevel()
{
if (stageSelect == 1)
{
Instantiate(Stage[0].stages);
stageSelect = 0;
}
if (stageSelect == 2)
{
Instantiate(Stage[1].stages);
stageSelect = 0;
}
}```
hi. i want everytime i complete stage it will go to the next one which i will put "stageSelect++" BUT it will keep update every frame on that instantiate which i do not want, any suggestions? i just want that stageselect to spawn only once ๐
sorry
By stage do you mean scene?
it didnt change scene. it is basically just "wave" of enemies but i named them as stage. its like once you're done with this wave, next wave is coming haha
What exactly is the problem? Do you not want the function to be called? If so, what function?
I want my instantiate to do it only once, reason i put stageSelect = 0 after select a stageSelect is because i want it to spawn only once. But now i want to put stageSelect++ everytime i completed that wave so i cannot put stageSelect = 0 however the problem of that is it will spawn every frame which i do not want. Any suggestion?
If you want it to happen only once at that point then why don't you just call the function there where you want to
yea? Or add a parameter before calling the function in update
Update is specifically called every frame
it sounds like you may want to look into events and/or coroutines here though, they will help you answer questions like "How do I run this arbitrary sequence of code over several frames/seconds once?" and "How does my spawner know when one of those arbitrary sequences has finished?"
they are a complication that isn't needed but, if you're doing that in Update, are probably missing from your toolbox and are powerful to know
ah ok. will search on that! thankss and thanks all of u too!
Any idea how to make an object go from point A to point B in a curved path, like half a circle
Bezier line! sebastian lague has a good tutorial for that
easy to understand
(targetPos - transform.position).sqrMagnitude > Mathf.Epsilon
what does the above line mean?
More or less that the distance(actually distance squared) to the target position is more than epsilon(an extremely small value close to 0)
ahhh got it
We always have the problem that when opening a UI element it is not resized correctly. This always affects game objects that are activated and filled at runtime (e.g. tooltips). I analyzed this and found out that ContentSizeFitter does not wait for TextMeshPro rendering among other things.
If something is changed (e.g. a text in the inspector) everything looks top. But independently unity does not get that done.
There must be a way to make this easier. Does anyone have an idea?
And how can I make the object walk in that path
You might need to manually rebuild the layout when the content changes https://docs.unity3d.com/2018.4/Documentation/ScriptReference/UI.LayoutRebuilder.html
Gimble Lock Issue (I think)
Hi all! l am currently having issues with a small "dungeon-like" generation l am making. In order to avoid the path overlapping itself, l have tried to use the Physics.OverlapBox() function to help with that but l am not very sure how to set it correctly, resulting in scenarios like these.
Each object l am making has a box collider, which gets used to determine the parameters needed in that function.
Here's where l have defined the overlapping function (l don't think there is need of showing what's in that Extension.DisplayBox() function)
what is Extension.DisplayBox?
l copied it from somewhere so l won't go and bother with Gizmos
ok so... what's the point of the overlapBox thing?
it's just setting a bool
are you doing aything with the bool?
Why is it running in Update?
What object is the script attached to?
the overlapbox's meant to get the NEXT gameobject that's about to spawn. Its box helps to see if it fits
next.Add(Instantiate(gbToSpawn[num],conns[i].transform.position,conns[i].transform.rotation)); //generate fake room to get box collider
conns[i].b = next.Last().GetComponent<BoxCollider>();
yield return new WaitForSeconds(0.01f);
if(conns[i].isHit){ //attempt to go to other way```
that's the point of all this
why not jsut directly do the overlapbox here
why does the object need to do its own overlapbox?
l use some "connectors"
and then you're doing this waiting thing, seems overcomplicated
so?
Well, it meant to make it easier
how does this make it easier?
well l just didn't want to fit that much into one entire class
Yeah l'm not very sure how to do it else
you're doing this:
- spawn an object
- wait for its Update to run
- in update if it overlaps comething it sets a bool to true
- you wait some time then check if that bool is true.
Wouldn't this be simpler:
- Do an overlapbox
- if it doesn't hit anything, spawn the object
- if it does, pick another place
- spawn the object once you've found a free place
like you have this whole extra obejct you're spawning, you don't need to spawn an object just to run OverlapBox
if you want, you can modify it
I won't
Yeah you are right
But l still don't get it why can't l just set a position and some start and end points to make that overlapbox
Would look slightly easier that way
At least in my perspective
you can
what's stopping you
How?
wdym?
l can't understand how to it
Just call OverlapBox with whatever parameters you want
no l mean why do l need to even give it a center
why couldn't be just a from vector3 to vector3
and just check whatever it gets in these positions
that's just how it is, but you can make a wrapper function around it that works the way you wish
hm?
just make a function that takes a "from" and "to" vector3, does a little math, and does the correct OverlapBox for it
This seems like it could be simplified by not using the physics engine and just comparing the bounds of each room manually. Then you don't even need to spawn anything until you've found a layout that works.
l have thought of that in the first place, but l can't imagine how should it be done
you can then even use a BoundsInt for this stuff
https://docs.unity3d.com/ScriptReference/BoundsInt.html
https://docs.unity3d.com/ScriptReference/BoundsInt.Contains.html
Do these bounds act like as boxes?
oh
l will give that a look
Never heard or used that type
An integer grid will definitely simplify things, but it doesn't look like your rooms are designed to fit inside a grid.
well it kinda works like tiled
each part consists of quads with the same size
I noticed whenever I do anything with either of these, to fade my audio out and in for a pause menu, it doesn't do anything. Everything seems set properly. I don't get any errors. Any ideas here? It doesn't do anything for either line here. Have tested both themselves and together here.
vehicleMixer.SetFloat("Attenuation", carVolume);```
What is that type actually?
PlayerPrefs?
In that case, if you think you can stick to that design constraint, you can use BoundsInt. Only thing is it doesn't have an Intersects method like Bounds to compare two bounds, so you'll need to write that yourself.
what's the difference with Bounds and BoundsInt actually?
l've seen other people doing stuff like IntVector2 and such
Bounds uses float and BoundsInt uses int
yes
it's for an audio mixer.
Nothing to do with playerprefs or anything like that
oh
Anyway l will try and give a better look
Thank you @leaden ice and @late lion for your suggestions
l will see what can l do
#archived-code-general message Does anyone know the solution for my question? Solved ๐
Does anyone have some nice code for fractal noise generation? I can't find any
That's also a great question for ChatGPT
i need help , for whatever reason the code in the 3rd image executes the code in the first image when it is supposed to execute the second when calling the Condition () function ; does anyone know if i'm missing something ?
!code
๐ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
oh ok , better way to do it , thanks
hold on, "new" to this
ok lets try this again , hello i have a problem where for whatever reason when i call my Condition function , the base form of this function is executed and not it's Ovewritten form ; https://paste.ofcode.org/uxf3dhF59PdUPTyxVXPLEt code here ,
does anybody know what i might be missing ,
the 2 functions are the first one on a base class and the second one on a 2nd class that inherits the first class
how do you call that function?
chilclassInstance.Contition(player,point);
https://paste.ofcode.org/CKgFbdZZc4anjsGmZpPvRj here is the snipped of code , i call it in the if statement
pretty much
Martial is the child class isntance?
or is it the instance is stored in a variable of the base type
yes, but the reference type is of the Inherited class
this one
funny thing is that this works with Other inherited classes and with other classes that inherit this base class
can you do
Debug.Log(player.AbilityInventory.Martial.GetType().ToString());
sure , good idea
the result is that it sees this class as it's base class
Ability_OBJ
UnityEngine.Debug:Log (object)
basic_melee:Update () (at Assets/Scripts/basic_melee.cs:28)
so you would need to change the type or cast to get what you want
funny thing is that it woks with a similar class , hold on ...
if you define a variable of type Collider
why would the code know that you wanted to use the Box collider that is stored in there
so it behaves like you wrote it
this class also inherits this Ability_OBJ class(and it is called the same way as my "problem class" ) and yet the condition function works as intended here
mind posting the variable definition
??? i'm confused, the martial variable definition?
cs // [SerializeReference] public Ability_OBJ Martial;
this one doesnt work
however
cs// [SerializeReference]public Ability_OBJ Lethal;
this one does
why would you expect a variable of type Ability_OBJ to be somthing other then Ability_OBJ if you don't cast it to a sub type?
maybe it is a fluke but
for me it has always worked (as long as i Override the function that i want to execute )
let me do a quick test
OH SHIT ; I FOUND MY PROBLEM
mmm wired
you where right it should have worked
thanks @proper oyster but i found my problem , i initialized by class wrong
aka i missed a constructor and it was creating it as Ability_OBJ class and not it's intended class
NONO, i'm grateful for any help , even if in the wrong direction , i might learn something new
this....
agghhh
Is it possible to have an advanced code editor (like vs code or pycharm) in a game, so the player can edit scripts? Is there a way to run a .exe File on Windows and somehow "capture" the gui as an image and display it in a unity game?
https://gdl.space/pojuyiqama.cs - Does anyone know why this code enables the player to jump infinitely in the air? It's a 2D game where the player should only be able to jump everytime the player lands on the ground.
don't cross-post
lets assume you can integrate it somehow
you could not distribute VS or pycham with your game ...
if you are looking into allowing some kind of scripting at runtime you might want to look at lua
yes
Vscode is released with the MIT License
so i can distribute it
how would you do this, with as little lag as possible?
And intelij is released with the Apache License, so i could distribute it too
If I was to do this, I would write a Winforms shell which I spawned from Unity
or better yet, a Winfoms shell which spawned the Unity build
i haven't heard anything about these things, can you provide a little more detail or an idea where i could find more information
This is obviously way beyond your knowledge or comfort zone, but just google Windows Forms programming
i googled it
thanks for you effort, but like one sentence what this is and how the image of the applicaiton gui would "go into unity"
because it seems like windows forms is a tool to code windows applications, but i want to "capture" them
what do you think a built windows unity application is if it is not a Windows forms program?
you're setting vertical velocity every frame so it never has a chance to slow down due to gravity
you need to apply a vertical impulse or apply an additive force over a set interval
Ok
So how would I go about doing that
If I spawn a sword prefab with ScriptableObj embedded in its references, will spawning a shield, with same SO embedded, create a second copy of SO?
you can use Input.GetKeyDown to check only the frame that a key is pressed
you can use ForceMode.Impulse for an instantaneous force
Rigidbody rb;
rb.AddForce(Vector3.up * whateverMyJumpForceIs, ForceMode.Impulse);
Thanks
is their anyway i can minimize unity standalone on a button click ?
vscode is built with electron
i mean capturing the image the application produces on the screen
Another way could be to use Vscode in a browser. Is there a reasonably fast way to have webbrowser in a unity game?
yes, and? It still runs as a Winforms program, this is why I said you lack knowledge
yeah ok, so you say there is a way to capture the image output from winform programs?
of course
and you are able to give mouse and keyboard inputs back from unity to the winforms applicatio?
oh boy
i'm getting the feeling that you're being aggressive unnecessarily, especially because either your conceptual understanding of windows applications is wrong or your vocabulary is inaccurate
would you call wpf and uwp apps "winforms"?
ok. i don't have any idea how to do this. What about using a webbrowser in unity? I've tried some "unity webbrowsers" but none seemed to work (last github commit 4 years ago type of stuff).
if you are talking to me, then of course wpf and uwp are not winforms, but winforms is what the default unity windows build creates
oh i thought you were saying that every windows application is a winform application
idk if there's anything already built in the asset store @swift falcon but you can build your own web browser for sure
we are talking about a unity build, it's not for nothing that unity has a separate uwp build platform
my instantiated objects are spawning like 1+e12 away..?
i'm setting the x position to something between 0-15
yeah but tbf uwp is its own unique thing, not just like a collection of class libraries
and it's deprecated so RIP all that effort
depends a bit for what platform since that is always a native plugin
https://github.com/Voltstro-Studios/UnityWebBrowser
yeah, but most of the assest store things are paid. I would need some kind of tool to render the html of the website into an image and display it e.g. on a texture, right?
I tried it, but it didn't work. It didn't open any webpages and just threw errors. Wait a sec, i have to open up the project again to know the error messages.
actually no, Unity has an Emscripten interface for communication with the browser for WebGL builds
yeah nice, but it says here that unity uses emscripten to compile into webassembly but that's far from what i need
then you are reading it wrong
As this started as a question about windows builds, neither do I
Ok, my question is again, how can I have a code editor for python inside a unity game, so the player can edit scripts. So my question is, if it is possible to run a windows application inside unity, so that the gui windows is "inside" the unity window, for example on a render texture.
The second sentence does not follow from the first
run a windows application inside unity
Seems like a very poor way to accomplish:
how can I have a code editor for python inside a unity game
Yeah true, but i want a high quality editor (syntax highlighting, autocompletion etc) but I'm definitely not able to code this from scratch in unity
I would approach this by including a python interpreter in my game and building out the UI etc in Unity
yeah ok, another idea might be to have a python language server running with LSP and using this data to power the editor features
how would you pull this off with an existing Python interpreter/IDE anyway? Wouldn't there be major licensing/copyright issues?
No, vscode and intelij are released with the MIT and Apache license
the very fact that you posited a render texture as a solution shows you have no understanding of what you want to achieve
what do you mean, if i want to have the editor on a "screen", that you can move around in 3d space, a render texture seems straigt forward
but a texture is just that, a bitmap image, not an editor workspace
But is there like an existing solution for a reasonable code editor UI in unity? I don't want to do everything by myself you know...
@swift falcon its a bit of work but that git package works
yeah, i know, but it could be the rendered image from, for example vscode, and the keystrokes and mouse movements are given to the vscode application that renders the image, which is then displayed on the render texture
ok, nice, what editor version are you using?
Doubtful. This is not a common use case
2022.2f1
but it should be working
2021.3.x and upwards
like the documentation says
(still some errors that i would have to figure out)
absolutely doable, which is why I said you need to learn Winforms
@swift falcon is this what youre looking for? https://assetstore.unity.com/packages/tools/gui/ingame-code-editor-144254#reviews
ok, my version is correct, but the thing is getting stuck after "Starting CEF client" and I'm getting this error
how to have 2 keys at a time on input manager on unity ?
yeah, I saw this too. But it's paid (big NoNo).
you need to start the client before you can use it
\Library\PackageCache\dev.voltstro.unitywebbrowser.engine.cef.win.x64@2.0.1-106.1.1\Engine~\UnityWebBrowser.Engine.Cef.exe
Alt positive
i mean the player has to press the 2 at the same time so it does the animation
just by running this in cmd?
just open the file
just add the && in the If statement of your code
if(Input.GetKey(key1) && Input.GetKey(key2)) //do stuff
like:
ok thanks i will try
use KeyDown to only trigger once
i want to do a running + shooting animation should i do it
use Avatar Masks
@swift falcon you might also need to setup some stuff in the inspector
I used the prefab from the samples thing
what ?
you have two animations you want to combine?
It's still not working, even when i start the engine
actualy i already combined in one animation called shot + run
so what is it you want to do
i just wanted something that triggers this animation
like 2 keys at a time
now ik
thanks
I have to start the engine before i start the game, right?
btw in && should there be a space between this and getinput ?
helps legibility
your IDE should automatically fix it usually
I'm getting this errror now.
yeah
wired it works for me
for some reason it tells me that the name of the key i put is not reconisable
even tho it's the same name
๐ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
My console output looks like this
you have to use three of these ` @swift falcon
{
if (Input.GetKey("Wforward") && Input.GetKey("Hit"))
{
GigaKnight.GetComponent<Animator>().Play("Hit + Run");
}
}
}
Hi I am currently working on the animation for my character but once I hit play it for really reason plays a random pose that was not included in my imported animation and stuck at that pose without changing to any others. the mesh of the character also moved vertically. Do anyone have any suggestions on how to fix it?
Anyone here a 3d modeler (if you are pls DM Me)
not the channel to ask
quit dodging the question.
if it's for collaboration, you were directed to the forums already
There is a warning by Unity stating "Animator is not playing an AnimatorController" but I have already plugged the controller to my player model and I am not sure why it is reacting like this.
Bro forms are dead
I set up the animator like this
show the animator component please? it'll be in the inspector
{
if (Input.GetKey("Wforward") && Input.GetKey("Hit"))
{
GigaKnight.GetComponent<Animator>().Play("Hit + Run");
}
}
}
are you referring the base layer?
here'
no. the animator Component. In the Inspector
the place you see your scripts on your objects. Show me the Animator component on it
what error are u getting
oh sorry
here
also that animation name is sus @swift falcon
Input Key named:Wforward is unknown
are you sure this is the only Animator component in your scene?
dont use strings, use Keycode for W
can you please type t:Animator in your scene search bar?
then see if there's an animator that does not have the Controller assigned
there is already one'
show it
Are you trying to use virtual buttons defined in the input manager? It's GetButton for those
this ^
It has no result after I searched that in my scene search bar๐
you hit this key on your keyboard and shift at the same time, multiple times
your SCENE search bar
there
Scene is where you see all your gameobjects in your scene
oops
i think it's called hierarchy
my mistake
thanks you so much :))))))))
thats just the name of your scene
also thanks
show the full warning please?
Trying the tutorial https://unity3d.com/learn/tutorials/topics/2d-game-creation/animating-bird?playlist=17093
When I run the game and the script does...
I googled "Animator is not playing an AnimatorController", if you want to find more info on it yourself
I googled that as well but I am not sure whether their solution will fit me or not since I think we are approaching the animation in different way๐ค
i'm having some trouble formatting a date string correctly
i call this function with the parameter being in seconds but i only get 00s 01ms, or if i remove the if statements and just set it to days and hours i get 00d 01h
i've debug.logged both the time and timespan and they're both accurate, it's the formatting that's not working for some reason
{
TimeSpan t = TimeSpan.FromSeconds(time);
string timeString = "";
if (t.Days > 0) timeString = string.Format($"{0:00}d {1:00}h", t.Days, t.Hours);
else if (t.Hours > 0) timeString = string.Format($"{0:00}h {1:00}s", t.Hours, t.Seconds);
else timeString = string.Format($"{0:00}s {1:00}ms", t.Seconds, t.Milliseconds);
return timeString;
}
Also I checked the value for my "moveAmount" ( the variable I used to decide so call the speed of movement ) it indeed has some values but the value referred in the animator is not seems to be receiving it as the value is not changing.
projectile doesnt destroy itself and doesn show particles when collides with bricks, what did i do wrong
Make sure OnTriggerEnter2d actually runs
make sure the OnTriggerEnter2D is actually being called
https://help.vertx.xyz/programming/physics-messages
and that the colliding object has the Bricks tag
Oh and Invoke is useless here, just call the method directly
i didnt know rb was required to detect trigger, thanks for help
How can I make an object follows a path from A to B in a curve like this?
Like how can I make that curve, and how can I tell the object to follow that curve (path)
Use splines
And this component to make your object move: https://docs.unity3d.com/Packages/com.unity.splines@2.1/api/UnityEngine.Splines.SplineAnimate.html
how to edit these two colors through script?
show the code for this script or wahtever you're looking at
or is this a particle system? What is it
stuck here:
transform.Find("Exhaust").GetComponent<ParticleSystem>().startColor.
yes
dont know if it belongs here as it is more scriptrelated
i saw that, but it only accepts one color, no? lemme try
No, it's a MinMaxGradient: https://docs.unity3d.com/ScriptReference/ParticleSystem.MainModule-startColor.html
thanks
OK thanks a lot, I will learn about it ๐๐ป
don't try to do everything on the same line
var mainModule = blahblahblah.main;
main.startColor = ...;```
it's a quirk of how C# treats value types that are returned from properties, combined with a quirk of how Unity designed structs like ParticleSystem.MainModule
Unity basically is abusing structs to act like pointers into their native code, and C# isn't used to structs that do that and assume you're going to shoot yourself in the foot changing a struct that doesn't actually get saved anywhere
Is there a simple way to have transform.TransformPoint(Vector3) ignore local scale? I tried dividing by localScale but I can't seem to divide two vector3's
use TransformDirection instead
Will try, thanks
take that back - TransformDirection should be right
TransformVector takes scale into account which is undesired, and TransformDirection doesn't seem to respect local space because I had it transform Vector3(0, 3, 5) and it just set my world position to 0, 3, 5. I guess I probably just need to add the result of transformdirection to the target transform's position
I think TransformDirection was the right answer and I'm being a goof
yeah so TransformDirection will work when added to the position
or you can do this:
Matrix4x4 mtx = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
Vector3 result = mtx.MultiplyPoint(theLocalPosition);```
transform.LookAt(Target.transform);```
what you sent makes sense btw
thanks for the insight and alternative approach
Why does ComputeBuffer.GetData allocate GPU memory that it never unallocates?'
it.. shouldn't?
it does
if it does that's a bug I suppose
if I call it 17000 times
I end up with 40 gigs of VRAM used
Anybody had issue before with netcode doubling their NetworkList? I used NetworkList for chest storage and when I launch host and put something in and then launch client and deposit something in chest either from host or client it duplicates the list content. So if I put 3 items there it will show 6. Strangely this only happens on first client load. When I close the client and start again, it works correctly.
that is a lot of times, but when you have a complex scene with l.ots of meshes...
and its a huge problem for me rn
it happens in 2021 and 2022 at least
maybe ComputeBuffer.Release handels that?
or that is only to get rid of the compute buffer
So wait are we talking about GPU memory or CPU memory
doesn't VRAM imply CPU memory?
GPU shared memory
hang on I got a screensho tof it
if I remove the call to GetData this doesnt happen
the climb in RAM and shared GPU ram
submit a bug report? ยฏ_(ใ)_/ยฏ
btw what I am doing is reading from a vertexbuffer into a compute buffer to then get it on the CPU
wanted to make sure theres nothing I am missing before doing so
Asking here because I didnt get an answer:
Anyone know why this code is causing the cube to rotate weirdly sometimes? I'm not sure what is causing it and it seems to only happen randomly. It might be an issue with DOTween but could not find anyone online mention it.
visualCubeTransform.DORotate(cubeRotation, 0.2f, RotateMode.WorldAxisAdd).SetEase(Ease.InSine);```
It should release the buffer, maybe it does not do it instantaneously.
shrug
it dont
I release the buffer manually
https://paste.myst.rs/nx036cnd
this code shows what I do
a powerful website for storing and sharing text and code snippets. completely free and open source.
Did you try to fill the memory by attributing and releasing memory and get an out of memory error or something like that ?
and the memory seems to ramp up. Did you go to the extreme and cause an exception ?
no?
this is on a yes highly detailed scene but still a normal scene
I dont think I understand what you are asking
You have an issue: Creating a buffer and releasing it seem to increase the memory used. If you isolate the issue, and do it till the memory is filled, does it cause an error ? Or the system continue to work as intended ?
no
the buffers are fine
its the call to GetData that increases memory used
and it crashes my PC when memory fills up
If it is really the GetData, I don't know what to say. Try to isolate the issue and replicate on a small project than do a bug report.
You have the Async equivalent, maybe it wont have the same issue.
It does not happens "randomly" it happens around -180. The sign of your cube change.
Why ? Uploading/Reading a compute buffer is not that hard isnt ?
no but it needs to iterate over lots of thjings
oh wait no I see what you mean
if its an issue with just the getdata, simply calling it thousands of times should be good enough
Yes, otherwise, you have an issue with something else.
yes
wouldnt make sense if its something else because it only happens if I use getdata, but we will see I suppose
hmmmm no its not doing it wtf
hrmmm
then wtf am I doing
is there anything wrong with my code?
Remove functionality till you do not have the issue.
I did
it didnt have the issue when I removed GetData
now im working in the opposite direction
I feel like it might be the SetBool or SetBuffer
You use Dispose, but the function is Release in the documentation. Is there anything I am missing ?
no they do the same thing afaik
using either produces the same result
hmmm I wonder... hang on
You could use the using key word also. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement
well the using keyword would call Dispose
so if Dispose doesn't work that won't help
I would expect Dispose to call Release though
or vice versa
Yeah, but it seems release call dispose
especially if they went out of their way to make these classes implement IDisposable
scope your code down, and you will eventually find the issue.
At the moment, there is to much going on.
I do highly recommend the use of using rather than manually calling Dispose though, if applicable to your code.
nah this was just an example, it happens at different rotation values
no idea whats even happening here
although thats with the code altered to work on both axis' but even so that sort of thing shouldnt be possible
visualCubeTransform.DORotate(cubeRotation, 0.2f, RotateMode.WorldAxisAdd).SetEase(Ease.InSine);``` different.y and x can only be 1 or 0
Input goes in Update and Physics in FixedUpdate right?
typically yes
ok so it happens when you access many different vertex buffers/meshes and then use getdata on the compute shader you sent it to
heres the CPU side of the code thats doing it
https://paste.myst.rs/hhj9mdcb
a powerful website for storing and sharing text and code snippets. completely free and open source.
uncommenting the GetData does it
wait lets see how much of the code I can remove
wait
one important thing, this is all being done in one frame
this is the new climb, with the dip there being a new frame
using doesnt help unfortunately
this is the minimum amount of code required to reproduce it
any ideas?
Maybe ComputeBuffer.Release is queueing it for the next frame.
is it not possible to release a compute buffer during a frame?
yeah thats what I am thinking... so theres no way really to fix this and keep it on the same frame then...?
is there ANY way to get around this?
no
because every mesh has a different vertex buffer
and I need a running sum kind of thing
you could still sum it all in one buffer
So im trying to store a score to use in another scene but i think that im not being able to call it because it isnt changing the value
https://hatebin.com/rrkvioyjmo
https://hatebin.com/ggrhvntcvu
true
I could run two things, one to count the length of everything and make the buffer
but thats still gonna be thousands of objects/buffers
Seem like what you are trying to do is impossible with the space you have available.
because my project has a hierarchy of root -> parent -> children
where the meshes live in children, and the buffers live in parent, and there are many children per parent, and many parents in root
Either you need them all allocated at the same time, which means you need that much memory allocated anyway (so what difference does it make if it stays allocated for the whole frame?), or you only need to do one at a time, which means you can reuse one big buffer.
uuggghhhh
so much work just to make it so I can read a mesh that isnt read/writeable
what ?
Is it all about that
lol
Just toggle the toggle
but I am making something for otherse to use
so while I could just toggle the toggle, itll be more work for others
toggle the toggle with code
wait you can do that?
lol
thought you couldnt do that to an already imported mesh
wait how do you do it on already imported meshes?
reimport them
but...
for others with say hundreds of meshes already in their project
you do it once
(and meshes that you cant do that to)
why you cant ?
static meshes, or meshes imported with the gltf importer
Are not read/writeable and donโt allow you to change that
And you need the mesh data on the CPU? You can't do whatever you need to do on the GPU?
Yes I need to to build raytracing acceleration structures
Why do you need to make a ComputeBuffer though? Can't you just read directly from the GraphicsBuffer you get from GetVertexBuffer?
Itโs in a funky format ainโt it?
Not any funkier than what you're already reading in the compute shader, I'm assuming.
Yes but in the compute shader itโs much faster to loop over everything and apply the appropriate offsets and such but Iโll look into the graphics buffer directly, very little info on it afaik
Why are you building raytracing from scratch ?
Compute shader based real-time pathtracer, able to handle millions of tris, been working on it for 2 years
it already exist doesnt it ?
Did you at least test Unity solution ? https://unity.com/ray-tracing#:~:text=Unity's real-time Ray Tracing,a photorealistic or stylized look.
yes? long time ago
Hello Everyone
but this also allows me to explore graphics things and implement them such as ReSTIR and ReSTIR GI
Anybody had issue before with netcode doubling their NetworkList? I used NetworkList for chest storage and when I launch host and put something in and then launch client and deposit something in chest either from host or client it duplicates the list content. So if I put 3 items there it will show 6. Strangely this only happens on first client load. When I close the client and start again, it works correctly. How is it possible that NetworkList has different value on client and server. It should be always synced right?
There is always a difference when you are doing thing to learn. I'm just making sure that you are not losing time on something that won't be profitable
mhm
I want to go into graphics research as my job as well
hmmm how do you get the vertexbuffer of a mesh on the CPU if you dont know its exact structure, do you have to have like 40 different structs, each with a different combo of elements?
No, you use array and size
You push an array with a size, then read from the array given the size
The type you use to push the individual point
Iโm watching a YouTube tutorial on aoe damage (my concept is a flash baton) in the tutorial he is doing this for a character. So his position is transform.position. Would I need to write something different so that the position it for the object I want it be attached to?
but its a vertexbuffer, it can contain normals, vertex positions, and UV's in the same buffer
on the GPU I would make it a byteaddressbuffer and read that but that doesnt work on the CPU
You can read it as a NativeArray<byte>
oh?
ok
tried it as byte[] but that didnt work, will try nativearray
Either should work, as long as you have the right length.
byte[] gave me this
How did you calculate the length of the array?
https://docs.unity3d.com/ScriptReference/Mesh.GetVertexBuffer.html
You can access the GPU copy of the vertex buffer directly using GetVertexBuff. This allows more direct manipulation of the mesh index data on the GPU, which can potentially improve performance. However, any modifications that you make to the index data this way will not be reflected in the CPU copy of the mesh data.
wyes thats what I do
but the vertexbuffer contains multiple kinds of data
Looks like there's no overload for NativeArray. AsyncGPUReadback is recommended by the documentation, to avoid blocking the main thread, but it also returns a NativeArray which will be easier to reinterpret cast into the data you need.
cant do that
the getdata allocates memory that isnt able to be freed until the next frame
A managed array won't be freed until the garbage collector collects it, which could take longer than a single frame.
it doesnt create CPU memory, it creates GPU memory
shared GPU memory
AsyncGPUReadback does?
GetVertexBufferStride, GetVertexAttributeOffset and related methods can be used to query the exact mesh vertex data layout and format, so that the compute shader can access it properly.
yes
but then I need a seperate struct for each possible VertexBufferStride
Are you sure? You mean you've tried using AsyncGPUReadback on the GraphicsBuffer returned by GetVertexBuffer and that allocated GPU memory? The examples you've shown so far all included creating a ComputeBuffer.
no
not tried it yet directly on graphicsbuffer because i cant think of a way to create an array with the same stride
You just need to match the byte length, which is count * stride
And then you can read it as a byte array
And reinterpret it later with the information you get from the vertex attributes.
doesnt work if read as byte array. get this
How did you choose a length for the byte array you created?
Try Data = new byte[MeshBuffer.count * MeshBuffer.stride]
What are you expecting to do ? You are uploading the mesh data into the GPU then releasing it every frame ?
no
reading the mesh data from the GPU back to the CPU
because it exists on the GPU for non read/write enabled meshes, but it doesnt on the CPU
And why you need to do it every frame ?
I dont
I need to do it in one frame one time
You memory is released ?
unity doesnt let it be released till the next frame
And why is it an issue ?
because for massive scenes, thats a LOT of data
Which is what your operation demands
yes
Could you not divide the operation in multiple frame.
not... really
I mean I could
itll just get really complicated
To be honest, if you truly want to learn. Maybe you should not use Unity. Unity seem to be more a pain in the ass then a tool for you.
oh it is
but it makes it easy for others to use and learn from
It should not matter whatever you are using Unity or not if you are trying to learn. I've use OpenGL to learn the basic of Graphic.
fair
There is a lot of tutorial on the topic.
And what is more, if you are going to work in graphics, you are expected to know theses API.
Direct X, Vulkan, etc.
yeah
Do your own engine. That is what you should strive for as a aspiring Graphic Engineer.
Sorry that I could not help you more.
its fine, thanks!
@zinc parrot Would it be possible to move the acceleration structure calculation to a compute shader and keep everything on the GPU?
I am actively looking into that tbh
its a complex acceleration structure but I know its possible, itll just be super complicated
Anybody knows Unity Netcode here? I am struggling with NetworkList sync. Somehow it breaks on client but only on first load. If I add 1 item to NetworkList on host, connect client and then increase value of that item it duplicates it on client. So client's list now has count 2. If I close the client and then connect again, it works fine. No idea why it's only happening on first client load and why NetworkList doesn't sync correctly.
I have a question concerning camera. I am making a first person view controller. I have my player and a component who follows my player and inside this component my player.
When I want to move my camera should I rotate the object contening it or my camera ?
#archived-networking maybe a suitable channel for this topic ๐
Actually Is a camera container really useful ? I have seen it in many project but not sure why it is used.
a camera container is useful if you want to do camera shake for example
You should avoid parenting your camera to your moving player, when you want to have a free camera look too
But if the container is just on root hierarchy and only holds the camera, it would make sense to rotate the container and not the camera to not mess up local and world rotation
Okay thx
Can we use Linq and is it cross platform?
yes and yes
It can produce garbage though so not recommended for things that happen frequently.
Yeah, until we get .net6+ in unity the performance is still not great
void CheckForTarget()
{
for (int i = 0; i < allEnemies.Length; i++)
{
print("search");
if (Vector3.Distance(allEnemies[i].transform.position, transform.position) <= targetDist)
{
currentTarget = allEnemies[i].transform;
print("tar");
isAttacking = true;
}
else
{
print("No tar");
currentTarget = null;
isAttacking = false;
}
}
}
This only detects 1 object in the array. The last one to be specific. Why is that happening?
Is it maybe because it loops once?
Even though it Prints "search" always and the loop runs in update
currentTarget is only one variable
it can only hold one thing at a time
and the end of the loop, it will be pointing to the last one it saw
currentTarget = allEnemies[i].transform; just overwrites the previous value
as does currentTarget = null;
Well it ingnores all other things in the array
wdym ignores
It overwrites, not ignores
what do you expect it to be doing
You need to keep track of the distance to the enemies if you want to get the closest one
what's the end goal of this code?
Right now you're looping through all enemies in a certain range and getting the last one in the array as a target
It can only See the circled one, cant see the others ones even if they are the closest
wdym by "see" and "can't see"
Because you are not checking for the closest one
how are you determining that
what are you trying to accomplish
Lets explain. If you have 3 items in your list, and 1 and 2 are inside your threshold, the loop would set currentTarget to 1, then to 2 and then check on object 3 and set it back to null, because it will never check against the last currentTarget if its closer or if its != null
So I need to find out the closest one, not if one of them is in a certain range
well your code is not even attempting that
If that is what you want to do then yea, you need to keep track of the closest enemy
its just checking if anyone is inside one by one and in the end use the last item everytime as return value
Right now you're looping through all enemies in a certain range and getting the last one in the array as a target
You'd need something along these lines:
https://forum.unity.com/threads/clean-est-way-to-find-nearest-object-of-many-c.44315/#post-281464
Alright @leaden ice @deft timber @plucky inlet ill do that right now
{
body.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
inAir = !Physics.Raycast(transform.position, Vector3.down, groundCheck);``` this is the code that is repsonsible for making jumping work in my game but it doesn't seem to work, not really sure what could be breaking it
What is "not working"
press space in game and I am not jumping, sorry for not clarifying
Did you debug log, is inAir ever false? And why do you check for it AFTER you check for the jump key? Is your if statement ever met, set a debug.log in there
just had a look and inAir was being set to true for some reason
@plucky inlet @deft timber @leaden ice Finally that stupid Bot works, thank you all
Someone understand this error please ? I have an issue with event i think
I thought it would be set to fale due to it being inverted at at the raycast
You made an event that calls a function called OnShoot, which doesn't exist
show your animation event
and show the code
I would try to avoid that inverting if possible. As you see, that just confuses. Make it grounded as bool and just check for a raycast being true.
yeah, have just done that and it is all working
thanks for the help
I think i have an error first here, because the debug log Debug.Log("PlayerInventory_OnWeaponEquipped"); never display
but debug log enter display.
I don't think any of this is relevant to that error
yes but i have issue first because i can't subscribe to event.
again none of this is relevant either
That show the onshoot event call
and the listener
than you're never either never subscribing or never invoking the event
add more logs to check when you subscribe and when you invoke the event to make sure those happen
that why i have put a debug log
i don't know why that don't listener since i call it
you need MORE logs
put a log where you subscribe
and where you invoke
not just in the listener
i don't understand you have the invoke and subcribe on the screen
and how am I supposed to know if that code ever runs?
You can write a nice complicated function and it's meaningless if it never runs
which one
the ones I keep talking about
i said to you that the enter debug log display
but not the one in the player script
ok that's one
what about the subscription part
and also how do we know that's the same PlayerInventory
this is subcription ?
same what
i do the same system as heal system and the event worked well
Okay. So I solved it if anybody has same problem I hope it will save you time. TLDR: NetworkList sucks. Or maybe just with custom struct. I just created list and synced it manually with rpc and everything works great.
what do you mean by instance
so i'm trying to make an item list with a scroll (button based)
and i have an button to go up, and a buttom to go down the list
and since i'm going through itens in a list and stopping once it doesn't fit the screen anymore i thinked of using an while loop
but even with multiple breaks on the loop it still freezes the editor
you might be in over your head
show the actuall code?
what
this function, its called everytime the button is pressed (the button also increases / decreases the scroll variable)
i'm still prototiping
still
why would you not cache it even for a prototype
no worth the time changing it later
still less work and faster to make changes
can just cache it locally before the loop
ok but the problem is that even after i force it to break the loop after 3 runs (a desperated attempt) it still freezes the whole editor
and whats worse
it only happens when the function is called the second time
well if it freezes it means your break condition is never hit
cause its called once the game starts just fine, but when the button triggers it again the whole editor just freezes
where are you calling this codfe
your break is most likely never hit
so your editor freezes
because of the infinite loop
debug.log it
would assume max anchor height never gets below zero
Do you need the while loop?
but whats the diference between calling it inside the add listner and outside?
its a undefined size list and i don't want to have an for just for 90% to be ignored
the whole idea is to break the loop once it cannot fit a new element in screen
well using an infinite while loop for that isnt a good idea
@leaden iceOk it is a script execution order issue
Idk why we need a script order for subs to event
I invoke a event but the other script that run after didn't started to subscribe.
That why i need excetuon order
no you just need to make sure the event is not invoked in Start
or move the subcribing to Awake
it depends on your usecase only different between awake and start is awake fires first for all objects then start
ok
Awake is to setup things like static instances and what not. Subscriptions usually can be done in OnEnable and unsubscribe inside OnDisable. at least thats my workflow
awake is just before start and on enable
does not matter if its doing static stuff or isntance stuff
can someone explain why putting that break down there makes the while breaks but the first if statement don't? isn't i++ supposed to increase the value of i?
But awake is being called once, while onenable and disable are being called everytime the object is active or not
So if you disable an object or remove it, the registered call si still there and will throw you an error
this wont stop happening bruh
if that 1st break is not breaking, then i is not greater than 3
i know how on enable and disable works, just pointing out you can use Awake for anythign you need to go before the other methods and its good for setting up internal state before soemthing else might access a object
Ok so my game work fine i don't see any bug but i have this error
but then it is supposed to break after running 3times, and that continue line should not be called since all elements have diferent names
its what i'm doing
pretty sure i will never get passed 2 since you always break the loop after incrementing
i donโt see anywhere else you change i
yeah that last loop, will always break on first iteration
but thats the point
really not sure why you even have it as a while loop
since you got the break if i > 3
that's what i asked him 10 minutes ago
that if has me trying to figure out why the while won't stop
so i try to force it to stop after 3 times to see if it would stop
use a debugger
debug it frame by frame
see if i is changing, just debug it
honestly your function is not well written and hard to read
it was not stopping because it was not meeting your conditions, just log or break point things 1 iteration at a time
i'm gonna rewritte this whole file
this is what i got for trying to change from one style to another
of scroll view
No one have idea ?
What are you trying to do again? sorry, cant follow up there ๐
Why i have this error ?
I don't see any bug with my shoot
so i don't know why he tell me something is wrong
i don't know what line is it; to what he refer
If you double click the error, its not sending you anywhere? or only on unity internal scripts I guess?
that select my player gameobject
looks like an animation event issue
thats has nothing to do with an animation event
does the compoent that plays the animation have a script with that function name
it is what you said before ? ^^
what is the issue ?
yes ? or the animation can't be played ? ^^
The problem might be, that your weapon is still having the OnShoot event registered even if the weapon does not exist anymore
My weapon should be here or i can't shoot xD
But the one you unequipped is gone?
you need to provide more context if you want to get help
i don't unequippe
when is that happening
if you delete the Animation Event
from your shoot animation
is the error still showing
how many times is your OnWeaponEquipped debug log being called?
i don't have animation event for shooting
shooting play a animation that all
If you comment out the OnShoot += line, the error is gone, right?
lmao no and i still can shoot
but the animation not playing
so idk don't look to be the event
So the error is still there? ๐ Interesting
yes
i even comment it on my gun script
for not invoke it
only solution for not have the error is to remove this
maybe he don't like the function name ?
0 reference and still even write error
even if i don't use it
int ?
SetBool() should have a string as first param, or am I wrong? You are trying to pass an int here?
oh can be both, my bad
So are you sure your animIDShooting is correct?
yes or the animation will not play ^^
even withtout call it that draw a error
i rename it 0 error
so idk the function name can't be OnShoot
maybe saved by unity for some reason
haha i know why that don't work
OnShoot is reserved by new input system
maybe is that
I dont think they have a default functino called OnShoot ๐
But i have one
on my input system settings
Input system send message to OnShoot function on my input script
So he tried to send message to all function with the same name i think
yeah if its on your specific input system settings, thats a user created thing. Then you could be right, but thats just to abstract to udnerstand over chat ๐
got it to work perfectly now, thanks everyone
Hello does anyone have a good resource so I can learn to code with C#. I have an idea of being able to move things in unity on a shelf and count the amount of liquid in the bottle i.e. a full bottle counts as 1.0, if the bottle is 75% full then it would say .75 or if it is 34% full then it would say .34. Can anyone point me the right way to learn this skill?
Do you use event for call animation or you just call the function?
just call a function look more easy that do another event again.
i discover event and overun it i think ^^
Yeah it sounds a bit weirdly setup or tested around ๐ hard to tell tbh
wdym
Hey Guys so sorry if I'm interrupting but I'm trying to make a dungeon generator for my game and I'm trying to spawn rooms next to each other which work but sometimes rooms spawn over each other and idk how to stop that from happening
Help would be greatly appreciated ๐
First image is room.
Here's script and example
See how in the images the brown rom is covered in blue now? here's script https://gdl.space/izatiridap.cpp
I am struggling to load a scriptableobject into a script at runtime
Check #854851968446365696 on how to share code properly.
i fixed it
So, you probably want to mark spawn points as occupied after spawning something in them. Or remove them from the spawn points list.
i just tried that legit right now and i get this error
i dont understand why i get it
Share the error details
k
What's line 43?
It's probably list being emptied. The index would be 0 at that point, but the last doesn't have any elements.
You need to check whether the list is empty and stop your invocation in this case.
but it still overlaps
No, you don't.
BUT IK WY!
You don't need to -1
See the white room
that overlapped the brown room at the bottom
But the reason it did that
was because of the brown room to the right.allrooms have 4 sawnpoints
so is there a wayto checkif something is at those spawnpoints before actually spawning the object?
Code it.๐คทโโ๏ธ
hi ,
quick question
if I want to get random number where the results should be a either ( 2,3,4 ) how to do that ?
Create a class representing the spawn points structure where you can mark/assign to spawn points.@tall lagoon
Check Random.Range docs.
@rigid sleet Sorry to bother you again! I'm trying to contact the Tormented Souls devs, as I've started a Discord exclusively for developers who've produced and released fixed multicam games (like Tormented Souls). Given the niche nature of the games and the unique challenges in constructing them, I thought it might be nice to have a place for Fixed Multicam devs to talk to their peers. =) If this sounds interesting to you (or if you can reach the TS devs and they're interested) let me know and I'll send you a link.
Unity's UI system always gives me trouble. I have an Image I'm placing on a canvas. I set the RectTransform's position to <56,0,0>, which I verified by debug.log. When I press play the image is created and its position is set to <515.5178,-33.98539,54.34146>, which is definitely not accurate.
The code is this:
HPNode n = Instantiate(nodePrefab, transform);
n.transform.localScale = Vector3.one;
n.transform.position = offsetPosition;
Debug.Log(offsetPosition);
Debug.Log(n.transform.position);
nodes[i] = n;
My console prints out the correct position twice for each node. But in the inspector its all messy. What am I missing here?
Use rect transform.anchoredposition
To set position
Same, its so boring compared to game mechanics
Is there a way to preview two different avatar's animations at the same time in Unity in edit mode?
I have two avatars I need to position, and their animations are synced. My problem is that when placing them in my levels, I can't see how they are aligned relative to one another.
For example, if two avatars need to sit side by side on a bench, I can't easily tell how to rotate them to get them to sit properly on the bench depending on what angle it's at, because I can only preview one at a time, so I have to keep swapping back and forth between them to preview the animation for each which requires a bunch of clicks for every adjustment in order to finally get them in a position where they are both well aligned with the bench.
I've tried opening two animator tabs and locking them, but that doesn't seem to work. I can't enable preview on the second.
I'm trying to use the unity job system and right now the biggest time user in my code is GC.Alloc because I'm passing so much data around.
I was wondering if theres a way I can reuse "old data" instead of having to make a new native array from a basic array every time I've tried using the "persistant" allocator but it seems like it still wants me to eventually dispose of it even if I dont update it.
Any help would be greatly appreciated.
Your Wait5 routine isn't right. And you can't use it like that.
Coroutines are kind of confusing at first.
Read that and if it doesn't make sense ping me. I'm going to bed but I'll help you through it tomorrow.
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it:
โข Visual Studio: https://on.unity.com/vshub (Installed via Unity Hub)
โข Visual Studio: https://on.unity.com/vsmanually (Installed manually)
โข VS Code* https://on.unity.com/vscode
โข JetBrains Rider: https://on.unity.com/3XgkeqG
โข Other/None: https://on.unity.com/3CYp2c9
*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.
Using Unity Netcode. I want the player to be able to drag a GameObject, but only if they have a particular resource (enough money to buy the sword, say). If I want to perform that check on the server rather than trusting the client, how can I do that within the context of the IBeginDrag handler?
Do an RPC to place the object, with the server ultimately placing it
oh no that part I can handle. It's just that I want to check if the player has the resources when they begin the drag. However, I can't do a quick server check for a value within the IBeginDrag callback.
Why do you need to check when they begin the drag
Because I don't want the drag to even begin if they're unable.
What does "drag" actually mean in this context
Is this a thing that's visible to other players
literally, a drag and drop. IBeginDrag etc. It's just a UI thing, the dragging of the card isn't visible to other clients
So then why does the server need to confirm or worry about anything
The client knows how many resources it has
because how else can the client know if the player has enough resources except by confirming with the server?
Presumably those variables are synced regularly, no?
Are you not constantly displaying them somehow
they're not synced at all, everything is on the server.
The client has no idea how many resources it has?
it's a turn-based card game, fyi. yeah why would the client know anything?
Why... wouldn't the client know??
It's like knowing how much mana you have in hearthstone isn't it?
Just because the server owns the data doesn't mean the client has no knowledge of it
yeah I mean i guess I do set the value on a text field periodically with the resource count but I feel like that's a bad way to store client knowledge
You're right it shouldn't be in a text field as a source of truth
There should be a synced variable for it
Hmmm
unity NetworkVariable
Sorry IDK the terminology in this particular framework so I'll assume Null is correct
yeah I'm thinking on that. the system used to be entirely class based and I am learning how to make it work by passing value only.
yeah Netcode.
it syncs with a property for you , kind of nice . reminds me of blazor
Is there a recommended app to use to animate a background on loop or character movements?
NetworkVariable also gives you proper callback support for keeping your UI text in sync
Right now I have kind of one big struct-of-structs that contains the gamestate, and I only let the server touch that at all. can I selectively put NetworkVars in specific spots for ones I want to check?
not code question.
asprite
idk what character is
maybe 3D? blender?
A bug struct of structs doesn't seem ideal for storing game state in general
2d
In fact "one big struct" already kinda violates the guidelines for what a struct should be
well i'm definitely still learning how to structure a game for multiplayer so I'm open to other techniques.
Game state is the kind of thing that would strongly favor a reference type, considering you'll want to reference it all over the place
well yeah but you can't pass reference types* through RPCs.
Passing the whole game state through rpcs is pretty inefficient anyway. If one tiny variable changes you resend the entire game state?
yeah actually I did move away from that but it's it's still a struct; it could become a class quite easily.
right now my RPC's only manipulate the game state; but there aren't any synced variables.
Lame. I can make an Enum a NetworkVariable<MyEnumType> but I can't have a NetworkList<MyEnumType>
Is there any asset which would give you a knife capable of slicing meshes into pieces?
idk of a store asset, but you can use probuilder for this
not ingame tho
its more for modeling
but you can cut stuff up for destroying if thats what u wanted to do
oh I wanted something for slicing limbs off
oh yeah idk of an asset, thats usually I use blender then with skinned meshes
How would you do it with skinned meshes?
You mean for slicing them off in predetermined places?
yeah I slice all the limbs in blender, get them into unity and spawn whichever one I need
I thought of slicing them off in arbitrary places
Idk, looks very difficult
Looks like will need to create entrails as well
Can start with cheese or something
i seem to have stumbled into an incredibly baffling bug. one of my components seems to have gotten stuck with a particle emitter effect on it, despite no longer having any particle effect components on it.
Oh there is this
https://youtu.be/BVCNDUcnE1o
I decided to learn how to slice meshes in unity. Going through Unities documentation I learnt that you can cut meshes by iterating the triangles in the mesh object and create new ones based on the intersections of a plane.
Subscribe: https://www....
these blasted balls of white light refuse to go away and i have no idea why @_@
...nevermind i think i found where the particle system was hiding
no idea how a rogue particle system ended up as the child of the highlight object in the project tree but im glad i found it
How to prevent this?
These are your troops, it's kind of a mix between 3rd Person Action and Strategy.
He wants to get to his position in the formation, but the big guy (player) is blocking his path.
Not really
Both navmesh and A* pathing should work for this, provided there is a valid path
Perhaps the player is not a navmeshagent so it isn't accounted for when calculating path?
Good point
Not with Speed: 8 and Acceleration: 200.
I need them to be fast and responsive, it feels really bad when you give them an order and they slowly start walking towards their destination.
He isn't, he has a NavMeshObstalce attached, so Agents don't intersect with him,
If he is an obstacle then you should be able to use this https://docs.unity3d.com/ScriptReference/AI.NavMesh.CalculatePath.html
And use the partial path. Im guessing you are just setting a destination directly
The obstacle isn't set to "carving" so the path is calculated as if the player wouldn't exist
Avoidance is only handled by the NavMeshAgent itself, in its movement.
Right
