#archived-code-general
1 messages · Page 358 of 1
for context im trying to add playfab into unity
it stores my email address as a string in one of the scripts
im after a way to hide it from being accessed anywhere
is your email address really that sensitive
It’s a playfab sdk issue then
eh i just dont want it being public
Make an email for that project then
yeah plenty of burner sites or make it on yahoo and they really wont want to email you
"who tf uses yahoo? must be a burner"
ill just use an alternate gmail one that I use for public stuff
not my main one so its fine
that wasnt your first idea? :l
i wanted to keep it organised and have the servers connected with my main email
i didnt realise until after i installed the package it stored my email address
While looking at stuff related to your question i found this very angry dev: https://discussions.unity.com/t/il2cpp-and-global-metadata-dat/795245/3
trying to use IL2CPP as an obfuscator of some sort
which btw even if you hid your email from that file it would still be stored as a string somewhere
im not 100% sure but im pretty sure il2cpp doesnt hide everything anyways
It can't
yeah
someone told me it turns it into c++ and binary
but then it can deassembled into pseudocode anyways
Libraries need to have public names so that they know how to call the methods
so the names of the methods and such will all still be visible
ohhh
that explains how someone made a mod of the beta of it then
tysm for the help btw
beta of what?
if its a unity game its extremely easy to mod
using unity engine is like 2 steps from a public repo lmao
i released a public beta just over a month ago of my game
back then I was using github servers but im transitioning to playfab as its more secure
oh, are you looking into ways to make modding/RE harder?
or is your email the only thing
i dont mind modding
im trying to avoid people hacking stuff
hacking stuff as in cheating?
yeah
or by using github as servers people could redirect the game to their server and get access to stuff
Guys, you are steering very close to a topic we do not discuss here
aight sorry
thought that was a solid one
is the one in middle a function ? If so why is written like this +=() =>
yes, that is called an anonymous function
and, in that use case is very bad practice
oh, yes, why is it done like that? I can only assume the person who wrote the code did not know what they were doing
what is the better way of writing it?
by writing a proper method which can be subscribed and unsubscribed to the event
can you show me how its done?
AuthenticationService.Instance.SighnedIn += ()=>{
Debug.Log("test");
}
await Authentication.Instace.SignInAnonymoslyAsync();
you mean like this?
I meant all of it but that will do
AuthenticationService.Instance.SighnedIn += OnSignedIn;
await Authentication.Instace.SignInAnonymoslyAsync();
...
void OnSignedIn()
{
Debug.Log("test");
}
void OnDestroy() {
AuthenticationService.Instance.SighnedIn -= OnSignedIn;
}
void OnDestroy() {
AuthenticationService.Instance.SighnedIn -= OnSignedIn;
}
what does this part do?
unsubscribes the event when the class is destroyed
note the difference between += and -=
ohhh ok thanks alot
I have a game where you control a ball by tilting the level course, trying to get the ball into the cup hole. The problem I'm having right now, is that my ball, which uses Rigidbody for physics and gravity - doesn't immediately respond to the player's tilting whenever the game starts. The ball only starts applying gravity when the plane is tilted very far. I tried to set the collision method to Continuous or Continuous Dynamic, but it doesn't change much. Any ideas?
Basic physics, it takes more effort to start an object moving than it does to keep it moving. You might want to make your physics materials slippier
i made a 2D snowboard game and I'm using left/right arrow keys to rotate the player. I'm using torque to rotate it. The problem is i built the project and when i start the game the player rotates really slow. But it works well in studio
I'm not sure if it's necessarily about the platform's friction, 'cause my ball wouldn't react to anything until certain occasions.
I had times where the ball wouldn't even touch the platform, or even go through it - and the ball would keep floating in the air, not reacting at all!
I thought you said it had a rigidbody, is it kinematic?
Yes, it has Rigidbody
No, it is not Kinematic (the option is not enabled)
sorry but there is no way a non kinematic rigidbody using gravity will 'float' so there must be something wrong with your setup
can somebody help me with my problem please? I'm new to Unity
Maybe the problem could be with the course itself, since I built it using ProBuilder - but the ball usually responds accordingly to the plane itself (whenever it's physics do work, obviously)
maybe, check all of the colliders very carefully
boxfriend asked for you to share the relevant code in #💻┃code-beginner. (Please don't cross-post 👀)
oh sorry
As I'll be checking all the colliders I have in scene - I also managed to record the problem itself:
Not sure if it will be that helpful, but maybe it will give an insight to what I'm trying to figure out at the moment
I dont know where your colliders are but that looks like they are not moving with the model
I tested again with colliders being shown in the inspector, and they seems to be updating respectfully to my controls (I'm controlling with my mouse btw)
Could the issue arise from the amount of vertices on certain game objects/meshes? My cup hole is the most complext object in the scene, as I have created it within ProBuilder
do it again and this time show me the ball, especially the rigidbody
nah, that drop of the ball says the rigidbody is the problem
Should I keep the colliders visible only?
no, thats ok, im only interested in the ball
I hope this close up should be enough:
Did I show what was needed? Anything else I could help with?
Sorry, you need to expand the constraints and Info sections
I opened it halfway through the video, but I'll try again
The same experiment, this time - the rigidbody component is fully shown from the beginning till end
Yes, you can see there between 19 and 25 seconds the ball should have speed at least from gravity but it does not.
Are there any scripts at all affecting physics or the ball?
As of now, the project only has 2 scripts: one is for controlling the platform, the other is for rotating the camera
No custom scripts are attached to the ball game object at all. The ball has these components only: Transform, Mesh Filter, Mesh Renderer, Sphere Collider, and the Rigidbody (and maybe the default material if you want to consider it too)
this is why I switched
But this issue has nothing to do with either input system
it has to do with the event system.
Also i recommended a solution for it already #archived-code-general message
alright you know what I'm a little lost on why I did it now too
there was a very good reason for it
I know that
sure but if you are going to decide "I'm going to switch to the new input system" then you should actually commit to doing that, including the costs of changing your code to the new system
Great! I will use it fix the problem accordingly
Also, another question if I could - is there another function to put it back into the sleep state, or is it better to just disable gravity whenever I want the ball to freeze/pause in time?
Have you tried perusing https://docs.unity3d.com/ScriptReference/Rigidbody.html
sure, check the docs, there is the Sleep method and the sleepThreshhold property
np, gotta say in all my years of using Unity I've never had to wakeup a rigidbody
How do I get a character to rotate according to its local rotation? I have a character running around a planet, but when I try to do this to get the character to rotate:
transform.forward = Vector3.Slerp(transform.forward, input, Time.deltaTime * rotSpeed);
the script uses world vectors, causing the character to fall on its side when walking on the equator. Is there an elegant solution for this?
rotate according to its local rotation?
Can you elaborate on what this means?
What is input and where does it come from?
if input is indeed a world space vector, then the code would work as is. So it sounds like input is not a world space vector
If input is a local space vector then you would just convert it to world space before using it.
input comes from another script as such:
void Update()
{
moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
}
public Vector3 GetInput()
{
return moveDir;
}
Also this code seems to be about moving not rotating
So yeah it's a local space vector
convert it to world space first, then you can use it in your other code.
Also make sure you actually want to move according to the player's orientation and not the camera's orientation, as those might be different and will result in very different behavior.
So, i am trying to get my game to pull up a windows system message, as a sort of meta thing (Like what OneShot does) but i keep getting an error with using the namespace "system.windows.forms" and i don't know what to do, help would be appreciated.
wdym by windows system message?
I have no idea what "OneShot" is
simple, you cannot use system.windows.forms in a Unity game
Sounds like something you would need to either import a DLL from or make a call out to some native interop code.
oh
ok, thank you for letting me know
@leaden ice So, my character can walk from the equator to the north pole just fine, but any other direction still results in flopping around. Maybe I need a completely different solution here.
Also, I do plan to have a toggle between player-oriented movement and camera-oriented movement
is this just for rotating
the code
@civic isle yes
have you tried something like transform.rotate quaternion.lerp instead
im not a pro but it seems like an odd way to rotate to me
Out of general curiosity - and this issue aside - how do you handle keeping the character oriented to the planet's gravity? Do you constantly move transform.up towards the direction from the planet to the character, or some such?
My issue with that is that rotation is already being set by a faux gravity script. If I try that, the gravity script will fight the player script.
@wide terrace Here's my gravity script:
public void Attract(Transform body)
{
Vector3 gravityUp = (body.position - transform.position).normalized;
Vector3 bodyUp = body.up;
body.GetComponent<Rigidbody>().AddForce(gravityUp * gravity);
Quaternion targetRotation = Quaternion.FromToRotation(bodyUp, gravityUp) * body.rotation;
body.rotation = Quaternion.Slerp(body.rotation, targetRotation, 50*Time.deltaTime);
}
I see - interesting. Thanks!
The character already has a rigidbody with rotation locked on all axes
lock the rotation in script in lateupdate perhaps
You would have to show the code you tried
I have a partially working script now:
void Update()
{
input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
Debug.Log(input);
}
void FixedUpdate()
{
transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(0, input.x*90, 0), rotSpeed * Time.deltaTime);
}
It can look left and right as expected, now I just need to get forward and backward working and I should solve this problem.
this isn't going to work if you're walking around a sphere
The other code you had was mostly fine you just needed to convert your input vector to world space
This script is attached to a child object of the player that holds the mesh. The main player game object has the rigidbody and handles the physics
Why not just:
Quaternion.LookRotation(input)```
Quaternion.Euler seems roundabout and... hard to work with here
...that actually worked better. All directions work now and i can walk on the sphere just fine now. Thanks for your help!
Could someone help?
NullReferenceException: Object reference not set to an instance of an object
SkillNode.Initialize (Skill skill) (at Assets/Scripts/SkillTreeSystem/SkillNode.cs:28)
SkillTreeManager.DisplaySkills (System.Collections.Generic.List`1[T] skills, UnityEngine.Transform column) (at Assets/Scripts/SkillTreeSystem/SkillTreeManager.cs:61)
SkillTreeManager.Start () (at Assets/Scripts/SkillTreeSystem/SkillTreeManager.cs:46)
Skill.cs is class without mono behaviour
line 28 is - skillNameText.text = skill.name
📃 Large Code Blocks
Use 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 format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
man, i though that skill.cs is null 
you have a condition that specifically checks for that
- question, does prefab store references?
it's also just skill in this case, not skill.cs because the cs file cannot be null
can you elaborate on wtf you mean by that?
so long as you aren't attempting to reference an in-scene object and are instead referring to something within the same prefab or another asset then you can
but assets (like prefabs) cannot refer to scene objects because those scene objects do not always exist. so you'd have to pass them to the instance of the prefab after it has been instantiated
https://unity.huh.how/references/prefabs-referencing-components
does anyone know how to code a API file I can give my users to upload their custom UGC content? I am trying to build it myself and it is very hard
ew, im stupid, i have panel with theese text's and buttons after i selected all of theese references in script i deactivated this panel
This would be a whole system, not just a "file"
At the most basic level though, it's just a datastore hosted somewhere on the internet somewhere.
What to actually use depends on what kind of content you want to store.
Less of a code question and more of an editor thing. But I am having an issue where a list on a scriptable object i created is being cleared whenever a change to a prefab that is attached to that object is added. Attached is the screenshot of the scriptable object.
Not a massive issue but majorly frustrating
are you perhaps doing something in OnValidate?
do you have OnValidate or custom editor for either script?
Nope, no editor changes or OnValidate calls
The only thing close to a editor change was i installed searlized dictionary addon that I am not using in any scripts but could that possibly be it?
not likely but techically any asset or plugin can cause issues...
Try restarting the editor?
Ive restarted multiple times since i first noticed
You're not using Dropbox or something are you?
I do see you have Version Control - definitely lean into that
Dats what I'm sayin
Man this is very annoying. It doesn't even really make sense. I have 4 instances of of the scriptable object, and its inconsistent on which is being cleared when a prefab is updated.
Wait, you guys don't learn how to code databases for UGC content???
Why would you code a database? Just use an existing one.
I might an idiot, but does that mean you used SQL databases, or is there some kind of easier option??
It really depends what kind of data.
You could use any kind of datastore, not just SQL
Depending on what you need
Larges amount of user avatar data, that has to be encrypted
Not sure what avatar data is but you could use S3 or something similar
can that run async and with users able to upload/download content onto the server while playing?
I've been using Backblaze for an S3 stand-in for various larger-data things recently... If you use Cloudflare to host the interface, data egress is free, which is super nice
wait, but how do you regulate content on it? I was going to seperate the content between age ranges, and graphic quality. Can it do that?
S3 is just a datastore
That stuff is all up to you
I'd probably use a SQL database for metadata
You're asking too much from general purpose tools.
You're going to need to write a web api
i did that, and it is okayish. Not the best, not user friendly, but for a test version it actually runs
As I mentioned earlier what you want is a whole system which will have many parts. A web API, a datastore for the actual data, a metadata store, authentication, and the client side pieces.
Potentially moderation of some kind if you're doing age range stuff
Yep, I know that. I have done 3 of that already. A test api, a way to turn content into meta data with a test file, no authentication, and on the client side I was working on that. I was just kinda hoping I can make it better with some advice
Well which part are you wanting help with specifically
Most of this isn't actually Unity related
the unity related part is, the game vrchat made this custom user uploader for content. I want to know what in the world they did to add there system to unity.
it is a literal extension to unity
I can show it if you want to see?
Adding extensions to Unity is well documented
but one that uploads user content isn't
Just sounds like an extension that calls a web api
I'm compiling (a mostly-empty project) with optimize for disk space and LTO for UnityWeb (WebGL for unity 6) and the linking is taking really long (20 minutes so far). Normal? The non-optimized build linking takes ~1 second.. I knew it'd take longer, but .. didn't quite expect this long
Also targeting wasm 2023 if that makes a difference
I will look more into extensions, thank you for your time
https://hastebin.com/share/ipifiginas.csharp why doesnt this work, it updates the location too fast
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Look at your if condition
You're updating the destination when it's farther than 1, instead of less
Anyone got a tip/idea for adding debugging text to the world? I'd like to staple some debug text in a specific place on a mesh.
I don't think I want to use UI since I'd need to raycast to the object and find some UI-space coordinate to display the text.. and move it around as the camera changes.. etc
I tried Handle but I don't think that's right, since AFAIK it only shows up in the editor, and I need some debug text in the build.
use a world space canvas
I don't understand. Just slap all of my world items under a canvas..?
just the text you want to display in the world
The Canvas/UI scaling is per pixel, and the world scaling is 1 unit = 1 meter..
or there's the TextMeshPro component that is not for UI
i don't see why either of the suggestions i provided would not work for that
So, cameras are moving all around.. I can stop them for what I'm working on, but I was hoping do throw a bunch of 3d objects down and print some debug information on/near each.
I didn't want to do a bunch of.. like.. figuring out where on the screen to display the text, though.. ie, calculating a screen position based on a world position and camera.. I was sorta hoping I could just slap a TMPro or Debug.DrawText or something on the item
right and you can do that using either of the suggestions i gave
Hm, there's a gap in what I'm trying to say or what you are and my brain. 🙂
Lemme do some screenshots, maybe
both of the suggestions i gave are in world space
neither of them have anything at all to do with screen space or the camera. they exist in world space like your mesh
OK - so I have my hierarchy parented like so.. no canvas on the world space items.. Do I just change the (existing) canvas to a world space canvas?
if the existing canvas has the stuff you want to display in world space, then yes. otherwise make another canvas and set that one to world space. then you just adjust its size/position accordingly
k.. standby, just playing around with the non ui tmpro
if it is just text you want to display, then that should be all you need. if you want to display any other UI objects, then you will need to go with a world space canvas
Yeah, just text for now.. just debug text
amazeballs, thanks
I didn't even need to change the canvas to worldspace.. just throwing the tmpro item on the 3d object and wiggling the rotation and scale and stuff around was sufficient
right because the non-ui version of the TextMeshPro component does not belong on a canvas because it is . . . not UI
the canvas is only for UI
yeah, gotcha.. I forgot there was a non-UI textmeshpro item.. I've typed "TextMeshProUGUI" probably 10,000 times in the past 3 years even 😛
My brain just went to.. using that component and figuring out a simple way to figure out where on the screen to render it .. instead of just making an actual TMPro component and putting it in the world, done
hey gamers, I'm making a spider. to anchor its "feet" to the ground I activate hinge joints. Id like the joint angles (for the foot ancho) to reflect the surface. I think I'm on the right track but maybe not. You can see the "foot anchors" in this image, basically I'd like them all to be the same, independed of the leg angle (given the surface it the same angle). If i can figure this out i can smooth my walking. (this spider realistically walks)
I'm on the right track - no pun -, I'm using raycasts and normals to assign the hinge limits. but I've lost the plot
@somber nacelle thx again.
just wanted an easy way to see cartesian/axial coordinates on all my hexes at a glance
Hey, I'm using XR and trying to pass an objects name on the OnSelectEntered Event in the hand's XR Direct Interactor. Is it possible to send the paramater that changes depending on whats picked up?
can i draw different meshes at specific positions using DrawMeshIndirect? i have some positions stored, some of the positions are for grass, some are for flowers...can i draw these two meshes at their specified positions at once or do i have to call DrawMeshIndirect 2 times with their respective positions buffer?
assuming you are actually referring to RenderMeshIndirect or RenderMeshInstanced (there is no DrawMeshIndirect, though there is an obsolete DrawMeshInstancedIndirect), it only takes in a single mesh because it is meant to render mulitple instances of the same mesh so you'll have to call it for each mesh you'd like to render
sorry, i meant DrawMeshInstancedIndirect...i find it handy to use, it says it is obsolete, but its is still working fine....so there's no way to draw multiple meshes at once, i got it, thanks
Is there any way to trigger the cursors “clickable” pointer state through code? Like for windows when mousing over a hyperlink the pointer changes to the click hand. Everything I find is just about Cursor.SetCursor which I theoretically could do but I am moreso asking for an easier way than changing the texture manually. Is there some api to use? Not sure how i can do this cross platform as well. Sure I could take the windows “hand” pointer sprite and set the cursor on mouse over. You see where im going with this, thanks!
is anyone here familiar with transform matricies? i’m up to some weird tilemap shenanigans
i’m trying to convert a tilemap that i imported from godot to unity, and godot stores three transformations: flip h and v, and transpose. i’m looking a matrix4x4 to get a start, but i’m not sure how i can apply certain transformations. it seems like there’s a transpose function already, but flipping h and v?
I need to make a planecast, or in other words "wide" raycast, is there a not crazy resource expensive way?
is there something specific you need it for? also wouldnt a boxcast just suffice
I'm trying to simulate a sword swing collision, but without any physical object
And the reason it needs to "sweep" from a direction is because I need to know in what orders it hit the colliders
a boxcast still should be fine
I guess it should, thanks for the solution
I wonder if a Boxcast would still work if one of its extends had a value of 0.
Would effectively turn it into a Planecast.
a plane spans infinitely, so its not really the same but it doesnt sound like a "planecast" is even needed
I guess planecaset would be the wrong way of calling it. Line cast? Wide raycast? But since box cast is here I'll try that
just use float.MaxValue on the extends 🙃
😢 Help...
when I execute this line of code
if (speakerData && isVisible && character)
{
Show();
}
this takes me into weird file called class PlasticApp and execute IsPlasticStackTrace() and execute bunch of other weird internal files and crash leaving this error message:
NullReferenceException: Object reference not set to an instance of an object
DIALOGUE.ConversationManager.HandleSpeakerLogic (DIALOGUE.DL_SPEAKER_DATA speakerData) (at Assets/_MAIN/Scripts/Core/Dialogue/Managers/ConversationManager.cs:114)
if statement just checks whether character has to enter the scene and make sure that character is not already visible or revealing
and Show(); is just altering alpha value to reveal the character.
I don't know why this 3 lines of code takes me to that weird files and crashes... Please Help
wdym, you don't know, these are obviously assets which YOU imported into your project
The debugger is running package code that's unrelated to your error.
Look at the stack trace you posted to see where the exception was thrown.
ConversationManager.cs:114
ConversationManager, line 114
Thanks, I didn't know debugger can run packages that's unrelated to my error.
I'll try spotting errors in ConversationManager, line 114
What might be your use case for something like this? If its only visuals you need, the other options you mentioned sounds fine, you could setup some kind of manager and event system to change the art for you so you dont have to do it "manually" if your concern is with having to write the same line of code several times
Quick question: I see this a lot in "more professional" code, when someone makes a list of something they often use, for example, private List<Collider> collider = new List<Collider>();, instead of just private List<Collider> colliders. Why would you do that, does it even make a difference?
The first one creates a variable and puts a value into it, while the second one just creates the variable with nothing in it.
If you try to use the second one as is, you'll get a NullReferenceException
Like when trying to add an element to the list (there is no list, the variable will contain null by default)
this is the difference between declaring and declaring + defining.
for value types you only need to declare, the define is automatic
for reference types (classes) you must declare AND define for it to be usable in your code
Sometimes the second option can be useful, in a case where you might want to initialize the list in a function that also populates it, rather than initializing it when its created, if the same case means the list might never get used
for some reasonw hen i hi the collider it doesnt follow the player it goes to the collider that it supposed to detect if the player it outside here are ther scripts https://hastebin.com/share/utosugaxiy.csharp https://www.toptal.com/developers/hastebin#
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I have some clickables that arent insanely obvious just want to change the cursor to show that. My issue with using what you describe is that on mac the mouse is different than windows etc so thats why I didn’t wanna set that up, that’s looking like the only option though I’ll probably just make a custom cursor with a custom clicked sprite and that will be my solution
Hello,
I've installed both packages XR Hands and XR Interaction Toolkit. However, the movement of the character is too slow and i was hoping to increase the movement speed. is there any slot i can store a speed movement or i need to create my own script for that?
you'd have to explain how you're moving your character
but - presumably on that script
Probably here
i believe it is through this input action map
i've added this component hoping that move speed would do the trick but nothing changed
but what about the locomotion system itself???
oh wait yes, it's the continuous move provider that does it
that is the whole inspector view of locomotion system
i just recently added the deviced based
neither one of those are doing the trick
or is it only applied through XR devices and not through XR simulator?
is coding a 2d game easy?
I mean that's what they do
im new
Simple games are easy
Complex games are harder
any game will be hard when you first start out though
because you will need to learn
oh this is my first time
im thinking of making a science game as a start
then you will have to do some learning and struggling
with stress
that's up to you ¯_(ツ)_/¯
Like i don't have VR devices to connect it out to the project. does continious move provider work only on VR devices?
csharp is the language right
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i'm doing my project via XR simulator which installed as extension from XR Interaction Toolkit
yahoo thanks time to cram it i need a prototype in the start of october lol
hey i have some questions about making a build in unity, when i choose certain scenes in the scenes in build section, for example if i didnt choose any of the scenes and did a build shouldnt the build be so small ? but now im trying that and the build is 600 mb, why is that ? and how can i fix that
Build includes whatever you're referencing in the included scenes + all the Resources folders in your project. Assets, like textures, meshes and sounds usually consist most the build size.
You can check what assets take how much space in the build by looking at the build report after the build is complete. The build report is printed to the log file.
editor log or player log ?
I don't understand? Why can't I remove a point from a polygon collider 2d???
You tell us. How are you trying to do it and what's stopping you?
I actually don' know what's stopping me.. I tried Ctrl+left click/right click on the point and even using delete or backspace but still won't remove the point...
You can remove it from the points list in the inspector, no? Anyway this isn't a code problem
I thought you were asking about how to do it in code
probably would be better in #⚛️┃physics or #💻┃unity-talk
oh my bad, I kinda don't know where to ask...
your good dude 👍
Is there an event that happens just before a domain reload? I need to save some process IDs with SessionState
check here maybe?
https://docs.unity3d.com/ScriptReference/AssemblyReloadEvents.html
Thanks
Hi all, is their a way to sample the same values from the gradient noise node in a shader within scripts? I am using the gradient noise to add some height displacements to different cells on a grid, but then also need to move the player up or down depending on the height of the cell. I was going to do this in C# as I would like to do some other things with these values too. Is this possible?
hey guys i have a problem about builds and i dont know where to post it
unless its code
im not sure if it has anything to do with code
its just that the build i make comes bigger than its supposed to be
it says that the base is ### mbs which i dont understand where they come from
should i post here or in #💻┃unity-talk ?
bigger than its supposed to be
and whats it supposed to be?
also doesn't seem like a direct code issue
all the scenes combined in the addressables should be something like 900 mb give or take, but after the build it says something about the base of the build or something being 500 or so mb and the build ends up being 1500mb, but when i check to see what is taking up the 500 or so mb in the build through the editor log i see that it says the assets are 900 mb
I see.. not sure about the problem sorry, I only dealt with addressable on a basic level :\
i see thanks anyway man, soooo should i post it in #💻┃unity-talk ?
yeah maybe try there first, this is a very specific problem. Post everything relevant as possible
goodluck 👍
Why doesnt the string.Replace method work ?
because you're ignoring the result
oh, thank you
string result = sceneName.Replace("Entry", "Main");
Debug.Log(result);```
now its working
strings are immutable in C#. So anything that modifies a string will always return a brand new one
sceneName = sceneName.Replace("Entry", "Main");
Is this a bad idea ?
it's fine
I mean I think this whole string manipulation thing is possibly a bad idea
but, that in particular is not
why do oyu think that ?
Is the package installed? You should look in the package manager
yes
do you have any errors in console
apparantly i need to delete the global cache of xr plugin management
but how
{hi}
Cool For Now on Im typing like this
Guys can you help me find preferences
anyone?
that's not a code question, but it is in the Edit menu
but i dont seem to find it
Go to #💻┃unity-talk and share a screenshot of the Edit dropdown
If you're on a Mac it's called something different. Settings?
playerID in body must match authenticated player```
After creating a lobby, when I exit play mode, start the game again and try to create a lobby, I get this error.
Here is my code https://pastebin.com/LbwDqQzs
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I'm pretty sure playerData.Id and AuthenticationService.Instance.PlayerId definitely match. Actually, I couldn't find what the error meant by "playerID in body".
so i've now learned how to make editor buttons
which is great
but I fear I shall spend an eternity making more
Could someone tell me whether i've over-engineered this piece of code? I wanted to essentially have a system where an input (e.g. [1,5,2,4,3]) corresponds to different spells/bullets in the game being fired in that specific sequence. These spells don't necessarily have the same behaviour, as one could be a slow moving projectile while the other could be a hitscan or something similar.
Since all of these have different stats and cooldowns, I've put this specific data in general purpose ScriptableObjects. I've also created a class that when passed an id or enum, will give you the appropriate scriptableobject (e.g. you ask it for Fireball, it gives back the attributes for Fireball). My next plan was to make it so that each of these scriptable objects also has a field for the Prefab which it corresponds to (e.g. Projectile, Hitscan, AoE effect etc.), which will then be picked up by the interpreter and instantiated. So for code, it's something like:
BulletAttributes bulletAttributes = this.bulletAttributesRepository.Get(bulletType);
GameObject bullet = Instantiate(bulletAttributes.prefab, position, Quaternion.identity);
bullet.GetComponent<IBulletScript>().SetDirection(direction);
bullet.GetComponent<IBulletScript>().SetAttributes(bulletAttributes, parent.GetComponent<PlayerStats>());
The idea being that this class picks up the prefab based on scriptable objects, and simply passes on the attributes to the prefab (this way the projectile's damage is not determined by the prefab but by the stats of the player and the spell). And various prefabs could then have different scripts for different behaviours. Does this seem about right for what i've described? Should I also maybe link the behaviour of the projectile to the ScriptableObject, rather than tying it to the prefab? Any other constructive criticism would be greatly welcome! Many thanks
Avoid repetitive code that is easily placed in a separate variable, like GetComponent<IBulletScript>() bere,
Also, consider splitting up your code so errors are clearer. Instead of inlining parent.GetComponent<PlayerStats>() place this in a separate variable and use that instead. It's clearer with errors and generally more readable
Good calls, I've just changed those 🙏
The scriptable object should be responsible of the instantiating of the object.
If you have a spell that shoot two projectile for example, you can handle that there.
Or if you have spells that do no shoot bullet.
oh, I didn't actually know I could do that with scriptable objects
I just assumed they're more like data objects of sorts, kinda unclear what they are exactly since im neither from a gamedev nor unity background
You can have function in a scriptable objects
that'd actually simplify stuff a lot I think, i'll look into it
I usually instantiate a POCO that handle the whole ability.
It makes it easier to have ability with casting time or different activation at different time.
Things like shoot 1 fireball, follow by 3 others 1s latter.
would you by chance have a reference or code example of using scriptable objects in this way (i.e. where they are responsible for instantiation of the gameobject), I've still got some gaps in my knowledge and i've seen scriptableobjects used mainly as data containers in the examples i've seen
public class FireBallAbility : AbilityDefinition {
public override void Instantiate(...) { ... }
}
What I prefer is to do something like:
public class FireBallAbility : AbilityDefinition {
public class Ability : Ability {}
public override Ability Instantiate(...) { ... }
}
I think i'm a bit confused, are these instantiate functions creating gameobjects in a scene or are they creating a POCO that is then instantiated elsewhere?
public class FireBallAbility : AbilityDefinition {
public override void Instantiate(...)
{
GameObject.Instantiate(prefab);
}
}
or
public class FireBallAbility : AbilityDefinition {
public class Ability : Ability {
public void Cast()
{
GameObject.Instantiate(prefab)
}
public void Update()
{
if(...)
GameObject.Instantiate(prefab);
}
}
public override Ability Instantiate(...) { ... }
}
does AbilityDefinition here inherit from ScriptableObject
yes
What does AbilityDefinition stand for there
The definition of the ability. Icon, description and statistic for inherit object
If you have other system it can use it
Limit on ability that equipped, categories
Ohhh you inherit this class from another ?
Tought the { was at the same line , was wondering if I had fully learnt C# lmao
If you do not know inheritance you need to review things.
hmm, okay I got something going:
//File1 - Bullet.cs (Ability equivalent)
public abstract class Bullet : ScriptableObject
{
public float speed;
public float cooldown;
public abstract float Instantiate(GameObject player, Vector3 position, Vector3 direction);
}
//File2 - NormalBullet.cs (Fireball equivalent)
[CreateAssetMenu]
public class NormalBullet : Bullet
{
public override float Instantiate(GameObject player, Vector3 position, Vector3 direction)
{
var bullet = Instantiate(prefab, position, Quaternion.identity);
bullet.GetComponent<BulletScript>().SetDirection(direction);
return cooldown;
}
}
//File3 - Shooter.cs = The shooting monobehaviour that handles input. Shoot is called based on player input.
private void Shoot()
{
if (_shootCooldown > 0)
return;
var position = transform.position;
var bulletType = magazine[_currentBulletIndex];
var direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - position;
var bulletAttributes = this.bulletAttributesRepository[bulletType];
_shootCooldown = bulletAttributes.Instantiate(parent, position, direction);
}
The bulletAttributesRepository in this case has an inspector where I pass enum+ScriptableObject instances, so I can create like 3 different assets of NormalBullet as upgrades of one another and just associate those with different enums. Sorry if this last part was unclear but i hope this is roughly what you had in mind?
this works fine for what that's worth, though some stuff could use polishing (like the way im handling the cooldown)
I know
Inheritance with classes , to inherit a class ?
Or you talk about something else
My English isn’t that good
Sorry if I don’t fully understand what you’re saying
Oh yea Ty I know it
But I don’t know what Instantiate is
If you know
Instead of naming things bullet and bulletscript you should name them bulletdefinition and bullet.
yeah naming should definitely be changed, im already confusing myself
would you say the rest is about right? I'm not experienced enough to know about any shortcomings of this, but I do already love how scriptableobjects can be tinkered with during runtime and then persist after stopping the game. Now I assume I'd probably want a new class for every single ability, unless that ability happens to have the exact same behaviour but different colour/speed/cooldown etc. E.g. with this i could create a fireball, a big fireball, an always-critting fireball etc., so long as those are fields in the attribute definition. Then if i suddenly need a seeking fireball, i'd probably be better off creating a new ability definition or something similar
You never use scriptable object as persistent data. Terrible idea.
For runtime*
in the sense that the data inside shouldn't be changed by the runtime you mean? yeah that's fine
The behave differently in a build and editor on that aspect.
i just mean as in tinkering with it
just to sort of be clear on that, what you mean is that for example I can store the maximum life of the player on a scriptable object and adjust it during development, but the actual current life should exist on a monobehaviour script, right?
assuming the maximum life can't be edited ingame or whatever
You cannot use ScriptableObject as save data. It really is not recommended to modified scriptableobject at runtime (not in the editor).
right, so basically use it like a read-only file
If you want to increase maxhealth because of a power up you do not modified the scriptable
that makes sense, thank you!
When I put .png files into my project, how do I have them import as "Texture Type: Sprite (2D and UI)" by default? I can't seem to remember how I've done this in the past, and googling is .. problematic, I just keep getting pointed at the inspector window for a texture
I have to do it in code? eep
I believe there is a template you can have, but never looked into it. I might be wrong though and it is another engine
I have other projects that I just drop png files into the project and they default to sprites.. I can't recall doing any code hooks for that
I may have setup those projects as 2d though
(ie - so unity did it for me)
K, created the preset, but unfortunately I still have to manually select the preset in order to apply those settings to the new textures
I thought there was a way to set up some sort of ... asset importer settings? but I can't seem to find it
found it
yeah, default behaviour "2d" makes new .pngs get created as sprites. 🎉
@steady moat can I ask you a question please
Just ask, no need to ping me directly
@steady moat curious about that example you mentioned of a fireball, followed by 3 fireballs after one second. Since scriptableobjects themselves don't have access to update callbacks or coroutines as i understand, what approach would you use to create that delayed effect
POCO or Monobehavior
What’s Instantiate in C#?
Nothing
Its a unity feature
And a simple function call
Ohhh
I’m new to C# , started 6 days ago , I finished all the W3sschools lessons and I haven’t seen yet a block of code where the { is at the same line , how’s it possible ?
They’re always at the next line
To encounter the block of code
what I wrote is pseudo code
and { after is only a style
which all c# use
as in pass a monobehaviour as an argument to the instantiate function and then use that to be able to schedule stuff?
public override float Instantiate(GameObject shooter, Vector3 position, Vector3 direction)
{
shooter.GetComponent<Shooter>.StartCoroutine(CreateBulletAfterDelay(1f, position, direction));}
or some more straightforward way. Also not sure how you'd do it with a POCO but either explanation would suffice!
Ohhh
Thank you
Didn’t know it was possible to choose it
public class DelayedFireBall : Ability
{
public void Update()
{
if(Time.time - startTime > delay)
DoFireBall();
}
}
public class Caster : MonoBehavior
{
List<Ability> activeAbilities;
public void Update(){
foreach(Ability ability in activeAbilities)
ability.Update();
}
}
Most of the time, the delay come from an animation though. So coroutine would not really work well there.
Also, you need to think situation where you would interrupt your ability.
Those are all great tips, thank you once again
I believe this is how most MMO/RPG type games handle this, they often have their own stylized cursor and toggle events (for example it may be visible when in a menu and hidden when in combat), that would allow them to swap the sprite for interactions like hovering over a lootable target etc, other options likely would be platform-limited
Im slightly new to unity and C# and what im trying to do is calculate a bunch of variables inside my script 'ChainGenerator' and then make those variables public so i can use them inside another script 'GeneratingChains'. The ChainGenerator script creates two empty game objects to use as refrence points, and then does some math to calculate four x and y coordinates that i need. (I have a desmos project that shows what its calculating if you curious https://www.desmos.com/calculator/3ipsvqux5b)
Right now i have the script setup to calculate all the variables inside the first script and the second script is suppose to call those variables and put it inside of a splines knot coordinates. im getting errors like "Assets\Scripts\GeneratingChains.cs(19,38): error CS0428: Cannot convert method group 'Ipoint4' to non-delegate type 'float'. Did you intend to invoke the method?" And im also curious if there is a better way of doing what im trying to achive.
ChainGenerator.Upoint1 is a function, not a value.
If you want to store a function, use System.Func or System.Action
what is the correct way to call it as a value, i just need its value?
Then you need to feed the function with parameter
Also, not exactly sure what is require to make a function be calleable in the variable definition.
on the first script i have it calculate a bunch of things then print it out to console, how can i use those variables that it prints out inside the other script?
float Tangent1x = ChainGenerator.Upoint1(0f,0f,0f);
ChainGenerator.Upoint1 is not calculated, it is function.
You need to feed its parameter to have the value.
float ipoint1 = Ipoint1(Point1y, Size1, theta2); //Y position of first tangent, i1
this is in my first script
I did not see the bottom part given that you did not use appropriate formatting.
But, if you want to access your value you need to expose them.
To be honest, this is really beginner level and it feels that you are missing core knownledge about programming in general.
Alright cool yeah this is what I ended up implementing. Thanks
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
just gonna throw this in there
https://learn.microsoft.com/en-us/collections/yz26f8y64n7k07
nothing beats good ol console apps knowledge / practice
I'd like my 3d models to "face" the enemy while they aren't actively moving. I'm .. not exactly sure what that looks like though.
My game board is hex based, roughly 10 unit radius, and there's usually 5-10 units per team (just two teams). If units on team A always face one way, and units on team B always face another, it looks weird if they "get behind" each other. If the units face in the last direction they moved, that's also a little weird if they're moving away from the action.
I was thinking of calculating a team's "center" and having units of the other team face that point? But I am not sure how to math up the center of an irregular polygon easily.. I could just do a rectangle, maybe? But maybe that's not what I want, since 9 units on one side of the map and 1 on the other is gonna be .. strange.
Maybe some sort of weighted center..? Or just face the closest enemy..?
you could also just... not do that. I haven't seen a board-style game that does that, tbh, you could maybe only face them when doing an attack animation or something
or face in the last direction the unit moved
or yea, closest enemy
the weighted center might actually be the easiest
if you want the team center idea, you can use transform positions to calculate it, it's accurate enough
add up all the vectors from the origin, divide the magnitude by the number of units..
that's a good way to achieve that, but I'm not sure if it'll be an effect you want
I have two scripts applied to the same game object, one inheriting from the other. Is there a way to fix having variables be duplicated across inherited classes? Am I using inheritance correctly? What would be the best alternative to maintain coupling? I'm only referencing _cardStats in the appearance class
I'd say on a hex grid units should face towards one of the neighbouring hexes
not an arbitrary angle that might be pretty weird during late-game
where units are everywhere
Just put CardAppearance (not Card) on the GO
CardAppearance is a Card, just with stuff added to it, as Sharping said you don't need to double up the Card
Okay, that makes sense. I was thinking I was intending to "display" the Card script in the editor, but I don't need to
oh, and this is probably not using inheritance properly.. the card appearance probably should just figure out what card it's using (card appearance shouldn't inherit from card since the appearnce isn't a card)
that's a good point
appearance depends on the type of card, but isn't a type of card
@plush ridge you should look up ScriptableObjects, your cards very likely need to be them
Okay so this might just be a good time to use a public variable with a private setter?
my bad, you're already using them
so .. you just want a reference to card in cardappearance:
public class Card
{
public Rank Rank;
public Suit Suit;
}
public class CardAppearance : MonoBehaviour
{
private Card _card;
[SerializeField] public Image Background;
private void Awake()
{
if (_card.Suit == Spades) Background.sprite = CardSO.SpadesBackground;
// etc
}
}
All good lol
since a card appearance has to have a card (if I understand correctly) then you don't need a public setter, just have the card appearance look for the card component .. at some point, depending on your game
that way you don't need to remember to initialize the cardappearance with the card
you just... set the card and the cardappearance takes care of itself
(but don't do GetComponent in Update() - it's expensive/slow - do it when you need to, once)
Now, am I correct in thinking that this would need a [System.Serializable] before declaration of Card, to appear properly in the inspector? I forget
[SerializeField]
specifically in this case where those are not monobehaviours
that too
they should be MBs, I was just pseudocoding it
I'm talking about System.Serializable for a custom struct to appear in inspector
or am I misremembering
w8 let me check really quickly
tbh, not sure, i've never serialized a non-monobehaviour for the inspector
I'll set it up that way. Thanks!
it does, I remembered correctly
it doesn't show up without
[System.Serializable] before Card declaration
Did things slightly differently but, what yall think?
private CardStats_SO _cardStats;
private void Awake()
{
_cardStats = transform.GetComponent<Card>()._cardStats;
UpdateCardRank();
UpdateCardAppearance();
}
public class Card: MonoBehaviour
{
[field: SerializeField] public CardStats_SO _cardStats { get; private set; }
@wintry crescent white box = enemies, pink box = "look at".. i feel like this works?
suppose I'll have to test it out in practice
obviously whenever a unit is moving or attacking, it'll face that direction
but when idling, the pink box seems like a good target
move half of the enemies to one side of the map, move another half to another side, and now everyone's staring at the center where there's nobody ;)
not sure that's what you want long term
but i mean, that's the same as them looking "at" each other
when idling, last direction moved should be the look direction I think
that's exactly what I want, i think
The problem is.. if you move a long range unit to the edge of the map then they'll have their back turned to everyone (until they next do something like attack towards the middle)
it doesn't work so maybe you shouldve listened to Sharping...
5 enemies on one side of the map, the pink "target" square ends up right in the middle of them, which is .. pretty much perfect, I think?
oh actually there's a weird edge case heh...
if the player is in between some enemies and the target, they'll be right close to that group of 3 but face away from them
you know what you could do?
👂
each unit has a sphere around it, and you do that weighted position things on surrounding enemies close to the unit only
maybe based on its range? or only taking into account units it can attack, for ranged units?
and if no enemies are in range, face towards last moved position, or that general point for the whole army, that you calculated just now
and maybe when calculating for meele/short range units, make the weights of more distant units less important
so that it prioritises looking at units close by, but still takes the ones further away into consideration a bit
Hm.. That seems like it's gonna be a bit complex/fiddly/error prone.. I think I can get something out of that, though, perhaps simpler
Like "heroes face right unless there's a unit within 8 hexes, then face the closest enemy"
maybe a bit fiddly, but I think it would be a cool effect
facing closest enemy seems like it's always gonna be useful
I'm also not sure (yet) if there'll be stealth units
worry about that when you get there
you could also just leave it at what you have now, and fiddle with the direction algorithm when your game is developed further
Yep, probably. I'm only a couple days in, but the timeline on this project is a bit tight. 😐
At least it came with some pretty cool 3d assets and animations
cute medic mouse don't take no shit 😛
don't worry about it then!! focus on the gameplay more, just look towards the last direction in which they moved or acted, that's it
that is pretty cute :D
what's your deadline on this?
Hi everyone, sorry for the repost of a question but its been a few hours and no one has replied so I thought it would be fine to ask again.
I was wondering if their was a way to get the output of the gradient noise node in a shader, but from a script. To explain, I have a mesh on the floor in which its nodes are affected along the y by a gradient noise node. I would like to calculate foot IK positions for the player using this.
The floor does not have a mesh collider as this is being ran on a grid of several 100 tiles, so I am directly rendering the meshes using Graphics.DrawMesh(...), the gradient noise uses the world position of the vertex as an input so I should be able to get its output in the same way through script. But I cannot find if their is a c# version of this call that gives identical outputs.
You would want to implement the same noise function on the C# side. Also Unity.Mathematics has a gradient noise function, and you can also either find one online or port the one from your shader
Does the gradient noise built in to Unity.Mathmatics give the same output as the shadergraph noise function? And if not how would I go about porting it from the shader?
Does the gradient noise built in to Unity.Mathmatics give the same output as the shadergraph noise function?
Test it out and let us know.
And if not how would I go about porting it from the shader?
By copying the code over and translating it to C#
Mathf.Perlin does not match either Simple or Gradient Noise
Not entirly sure how to call the Mathmatics noise functinos but Ill give that a try next
pnoise and cnoise also do not match
Cinemachine has an inbuilt camera type for this, you just give it all objects to follow and set up when to ignore enemies (when they are too far) and it even zooms in and out for you if they get closer
https://img.sidia.net/ZEyI5/rIYOmUta83.mp4/raw
here is the discussion about how it works i had some time ago: #🎥┃cinemachine message
awesome example video..
using TargetGroups?
Yes
Camera's no problem, and I'm already using Cinemachine.. I was talking more about what the units should look at.. Unless you're thinking of something else I'm misunderstanding?
Oh no then i missunderstood a bit, but i think you can also use a cinemachine targetgroup (without the camera) and use it for your purpose, as a look target
Yeah, like I mentioned, that's all taken care of.. The user has control "normally" so they can move their VCam around however they want, but then we have a VCam for each unit and we blend cams into theirs whenever they do something interesting
Although one thing I hadn't thought of yet was when one unit attacks another.. Doing a targetgroup might be nice there to let cinemachine just show us a nice blend of both targets without having to manually fiddle it
a couple months.. sept
Well I've just tested to see if I get the same results using the code example for the LegacyMod version of Gradient Noise (Deterministic doesn't seem to exist in the docs https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Gradient-Noise-Node.html) and I'm still getting different results. My guess now is that either the maths is wrong from what I think its doing or that their is a difference in precision with Vectors functions and shader floats.
private Vector2 NoiseDirection(Vector2 position)
{
position = Mod(position, 289);
float x = (34 * position.x + 1) * position.x % 289 + position.y;
x = (34 * x + 1) * x % 289;
float temp = x / 41;
float fractionalValue = temp - Mathf.Floor(temp);
x = fractionalValue * 2 - 1;
Vector2 vector = new Vector2(x - Mathf.Floor(x + 0.5f), Mathf.Abs(x) - 0.5f);
vector.Normalize();
return vector;
}
private float GradientNoise(Vector2 position, float scale) => GradientNoise(position * scale) + 0.5f;
private float GradientNoise(Vector2 position)
{
Vector2 ip = new Vector2(Mathf.Floor(position.x), Mathf.Floor(position.y));
Vector2 fp = new Vector2(position.x - Mathf.Floor(position.x), position.y - Mathf.Floor(position.y));
float d00 = Vector2.Dot(NoiseDirection(ip), fp);
float d01 = Vector2.Dot(NoiseDirection(ip + new Vector2(0, 1)), fp - new Vector2(0, 1));
float d10 = Vector2.Dot(NoiseDirection(ip + new Vector2(1, 0)), fp - new Vector2(1, 0));
float d11 = Vector2.Dot(NoiseDirection(ip + new Vector2(1, 1)), fp - new Vector2(1, 1));
fp = fp * fp * fp * Add(fp * (Subtract(fp * 6, 15)), 10);
return Mathf.Lerp(Mathf.Lerp(d00, d01, fp.y), Mathf.Lerp(d10, d11, fp.y), fp.x);
}
private Vector2 Add(Vector2 vector, int integer) => new Vector2(vector.x + integer, vector.y + integer);
private Vector2 Subtract(Vector2 vector, int integer) => new Vector2(vector.x - integer, vector.y - integer);
private Vector2 Mod(Vector2 vector, int integer) => new Vector2(vector.x % integer, vector.y % integer);
This is the C# code I am using
This is the comparison
This is the shader also, all it does is sample the perlin noise and add to the y position based on the output. (sample is based in world positions)
If anyone knows where this could be going wrong I would appreciate it
You can look at the generated shader code from your shadergraph and see exactly what the code is doing, or you can make a custom function to use as a node in shadergraph that will have whatever calculations that you want in it, so you could port a C# noise function to the shader language to ensure its the same
I don't know what's going wrong but those are my recommendations
currently pulling my hair out and failing miserably with any attempt i've made to create a pixel-perfect UI. ONLY the UI. if anyone has any tips or suggestions i'd appreciate them
(ignore the no cameras rendering that was just me messing with render textures)
You'd have to explain what trouble you're having with it. Also this is a code channel. Are you looking for #📲┃ui-ux ?
oh that would be better thank you
sometimes (rarely) my game crashes because there is a call to a function on a component on the same frame that it is being destroyed. Is the fix to check if gameobject != null in every public method on a script which may be destroyed at runtime?
no you have a code design issue prob
null check is a good start, but can be a bandaid
what are other solutions? The only other I can think of is setting internal state onDestroy and checking that
it all depends what you're doing and why its being called within same frame
null check should be fine
it seems to be random because it just happens to receive an incoming call on the same frame its destroyed. For example a playerController telling a weapon to fire on the same frame its destroyed. Could it be I'm not destroying things correctly and if I destroy both on the same frame it shouldn't be a problem?
null check definitely works though
if you don't mind the performance drop you could try destroyimmediate
that solution is also a bandaid though
some part of your code is working on an incorrect assumption that the object still exists
try attaching a debugger and look at the trace when you get a object is destroyed error
hey guys does anyone happen to know how I can shrink the "extrusion" of the tilemap so that the collision line matches the orange line?
i tried changing the extrusion variable in the collider but it doesnt show any difference for some reason, and ive been googling for an hour but its too vague and i cant find anything related
it works if I manually shrink edit a cell and then apply the manually made border, but theres a better automatic way right
wtf
i did nothing and it fixed itself
Maybe you should try moving your question to the appropriate channel #archived-urp #💻┃unity-talk or whatnot
I'm having trouble getting this to keep the clip I'm assigning to the AudioSource, can't figure out why.
The context is it's the pages of a storybook, and some of them have background music. The music all needs to sync up, so I need to have the pages with music playing at the same time but the volume down until the page is on-screen.
Because that would be a lot of audio clips, I de-duplicate based on asset path and create a list of pages for each audiosource.
When I do all of the below the log output is correct but the clip is blank in the inspector:
private List<BackgroundMusic> MusicList = new List<BackgroundMusic>();
private List<InstantiatedBackgroundMusic> Instantiated = new List<InstantiatedBackgroundMusic>();
public IEnumerator Init()
{
for (int x = 0; x < MusicList.Count; x++)
{
bool foundInstantiated = false;
for (int y = 0; y < Instantiated.Count; y++)
{
if (Instantiated[y].Clip == MusicList[x].Clip)
{
Instantiated[y].Pages.Add(MusicList[x].Page);
foundInstantiated = true;
Debug.Log("Music: Added another " + MusicList[x].Clip.name + " to Instantiated for page: " + MusicList[x].Page);
}
}
if (!foundInstantiated)
{
InstantiatedBackgroundMusic ins = new InstantiatedBackgroundMusic();
ins.Pages = new List<int>();
ins.Pages.Add(MusicList[x].Page);
ins.Source = gameObject.AddComponent<AudioSource>();
ins.Source.loop = true;
ins.Clip = MusicList[x].Clip;
ins.Clip.LoadAudioData();
Instantiated.Add(ins);
Debug.Log("Music: Added " + MusicList[x].Clip.name + " to Instantiated for page: " + MusicList[x].Page);
yield return null;
}
}
}```
here's those two data types
public struct BackgroundMusic
{
public int Page;
public string AssetPath;
public AudioClip Clip;
}
public struct InstantiatedBackgroundMusic
{
public List<int> Pages;
public AudioClip Clip;
public AudioSource Source;
}```
I'm loading the audio clip and storing it in BackgroundMusic, then passing that on to the data structure that holds the actual AudioSource. The debug output definitely has the name of the clip, but where I assign the clip above doesn't seem to be working
does anyone have any idea why my clip isn't making it to the AudioSource component? all of the other changes are, e.g. turning on looping
i might be blind, but where do you actually assign the clip to the audio source?
wondering exactly the same thing
yeah that was it, thank you 🙂
Hi all, just wondering, is it common to have some known bugs/errors popping up in your console that you can't get rid of, and you just live with it? Or am I doing something wrong?
Can you be more specific?
I've posted on URP channel hoping for help, here's the error Im getting. From time to time I also get some GUI related error that I don't think is caused by my code?
Just wondering is it normal to have some random errors from time to time and you just clear it when it pops up haha
unfortunately, yes it is, especially whrn you have Animation and UVC tabs open
Phew at least Im doing doing things TOO wrongly hahaha
it is unfortunate, but with Unitys internal move to using UIToolkit, they didn't test things very well
which is why a lot of spurious GUI errors spring up
would I be missing anything specific if I went from VS community to VS Code + unity extension?
not a code question #archived-lighting I would guess
ah kk
oh wait nvm i just had to turn self shadows off wow
Try switching the order. You're likely just measuring a JIT compile, which only happens the first time a method is run.
== null and == default means the same thing in this context and gets compiled to the same thing. default is null for reference types like AudioSource.
well f
Is it good to sometimes re-write a script if I am making a large systemic change?
yes
it's called refactoring
why does the second screenshot have the minecraft font
ok good to know :)
That's my VSCode font
For some reason my brain can't accept it on any other IDE
So it's only in VSCode
Hey guys, not really a coding question but I mainly talk here so figured I would ask here as well
Don't you sometimes feel like games aren't fun anymore? like I would play 10h+ hours of league a day or hearthstone or whatever but now it does not really do it anymore?
Even the game I'm making is "pretty fun" but I don't "addicted" to it per se?
How do you guys deal with that (especially working in the game dev industry where well, we do it by passion most of the time)
It's this one https://github.com/IdreesInc/Monocraft
damn lol
I'm not an advanced dev by any means, but I can answer the question. It's called change of interests / priorities. You have to manage many other things as you get older, and interests change as well. Thats life :). Lack of free time could also be an issue. But you also have to ask yourself. Are you happy that you dont player 10 + hours of games every day?
I mean I guess it is more of a lack of free time issue.
Also, it used to be that gaming was the default activity
not really true anymore
oh yeah it doesn't matter to me
that I don't play so much
my problem is more about not liking games as much as I used to
so that I'm less interested in making games (?)
and that sucks
Maybe you just like other things more and that makes you think that you like games less.
not really (?)
Do you still like making games?
yeah sure
But for instance
I used to be like "omg i'm going to remake monster hunter it's going to be the greatest thing ever"
but now I feel like "meh" about it(?)
although admittedly, I did code 12h a day for a month straight
at this point
maybe that has to do with that
Thats fine man! You don't always have to have the same interests throughout your life. That's just the way it works! If you don't like playing games, don't force yourself to. If you dont like making games, do something else for a while. Life is all about change, and nothing ever stays the same. Sometimes ppl find something they really like and stick with it, but you shouldn't put pressure on yourself to like the same thing all the time.
As I said change of interests :)
But then, I don't really have spikes in other interests
so more like decrease of interest?
burnout, maybe
without spike in others
if you worked so much
prob this aswell
working 50% more than full time for a month straight
you need to pace yourself friend
or else you're gonna burn out and this will keep happening
chill out, slow down
isn't it necessary though to start your career?
no I mean
I know what you mean
I have 1 month of "free time" left
but you need to take care of your brain
yeah sure
and you're not gonna do anything with it if you don't take care of your brain
don't work this much, this is not sustainable
long-term
it'll burn you out, it already has to a degree
You should always work on your project, make time for it. It's better to consitently work on it then trying to do everything one shot.
yeah maybe I should take days off from time to others
I tend to skip the weekends too
yea that is not very good
you actually need to do other stuff sometimes
yes
Usually, people works fulltime and do a game part time.
Yeah, you're right
The thing is that it started as a 48h game jam (early July) and I have been coding it ever since as I did not want to waste any art asset
I also just wanna say (to balence out what I said above) it could just be burnout, not change of interest. This could be the problem with the gaming aswell
Those assets are not going anywhere ?
you're not gonna waste art assets if you just chill out on weekends
Well, I just really want to avoid the scenario where we just don't release the game because I did not program everything (?)
It does not need to be done in 1 month ?
I mean kinda
Then scope down.
Most games takes years to come out WITH a team of programmers, artists, musicians etc. So you dont need to pressure yourself into doing it all in 1 month
Well, right now I only have like 1 boss left to program out of 4 levels (each level has an enemy with a specific mechanic and a boss fight)
okok
Though it does feel bad to scope down
It's like I'm "giving up" on the game in a sense
how advanced are you? how much of the game is done
Like for instance, I had a boss fight where I wanted snow to rain down the screen and I never worked with ParticleSystem before
well that took a day
but I can't imagine the game without it
Not really though, it is standard to scope down games.
I think I have 2~3 more days of work left
so not much
Then try to complete it if you only have that much. But take brakes
Also, get feedback that is very important
One other thing that I realize when I thought I didn't like games anymore was that I didn't spend much time on level design on one level
which made the level tedious
that was another thing also I guess (now it's way better)
How do you get feedback typically?
Make a devlog https://discord.com/channels/489222168727519232/1180170818983051344, and then ask in unity general or smthn
okok
Well thank you a lot for your time guys
I'm going to take a nap, have a good one !
see ya hope we helped :)
GL, cant wait to play it :)
A big part of my thought process was that playing video games feels like a "waste of time"
Btw, Can you @ me when the game is done? I wanna play it :)
whereas when I was a teen, it was more of a "potential career"
oh for sure man
It's a metroidvania (?)
It's like my third small game
but it's bigger scoped than my previous ones
They can actually be a good way to study the mechanics. The camera movement for my first game, I am basically copying from hollow night
Ooh I love metroidvania's
I mean I'm not sure if it's a metroidvania but it's more of a 2D side scroller fighting some monsters type of games and there are a few platforms but no death pits (?)
Does that qualify as a metroidvania?
The second level is pretty fun
I want to spoil so much
ok just 1 thing
level 2, the small bears throw seeds on the rhythm of the music
like in new super mario bros for the koopa troopas (yes I did not want to scope down this because this gives soul to the game lol)
Anywhooo
Really going to take a nap now
I work night shifts at the moment
see you guys 🙂
can I just ignore "Assertion failed on expression: 'SUCCEEDED(hr)'" error if it does not affect the game at all?
it appears every time I create new project or open old one
yeah probably. How old is your unity version?
I used to get those in a very outdated version of unity
I tried multiple versions, 2021.x 2022x and even unity 6
ah well thats odd then
Might be my GPU
yes try updating your GPU drivers if you haven't done so
or do you have an onboard gpu maybe?
Does anyone know what persistent malloc is? accumulates a lot of memory in the memory profiler
would be nice if we had a #profiler type channel only dedicated to analytics and performance chats
all my drivers are updated
not sure how true this is, found it on google
so my current solution to this is
menu: Edit > Project Settings > Player
on the inspector go oher setings
unpick auto API for windows then click + sign select direct3d12
drag it above direct3d11
apply
switching it to 12 idk seems like placebo but some peopel say it worked
yep I tried that too
I'll try downloading even older version
Hey guys, I have some errors in the PlayerControls script. So I was just adding a new action in my Input Action but suddenly there's so many errors and i don't know how to fix it.
ima send the code
the errors looks like this
these errors mean you have a duplicate script
ooh
you probably generated it twice in differnt places
okay, I'm gonna check if there's any duplicates
yep, i found another script
thanks for ur help!
what is the problem here??
Your network manager Singleton reference is null or it doesn't have a NetworkTransport component attached
Basic NRE stuff
Is it possible to save serialized values into a single downcasted list, or do i have to save them seperately lists based on their types?
Possible just not with JSONUtility
would I have to create a completely custom serializer for this? or would it be possible with unity's scriptable objects/yaml serialization?
Completely custom? It depends what we're talking about here
Are you talking about Editor stuff?
yes
If it's editor stuff you can use this to customize the serialization:
https://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.html
bleh, I was looking at that earlier, and it seemed like a pretty ugly approach
but i guess I could probably figure something out with some reflection here or something
Hey, im trying to make my camera move when my mouse is close to the border but i have no idea whgat i mdoing and its not working
heres a quick sketch to demonstrate my intention
What's not working about it
Oh I see. You're assigning the camera position to the delta instead of adding it
The last line should be += not =
he sets the camerapos to the initial transform, so from the beginning it is doing this
Scientific notation because your numbers are incredibly large
il send a clip of whats going on rn if i play
1e1 = 10
1e-1 = -0.1
2e2 = 200
etc..
oh cool
i have no idea whats the problem
oh, you're just panning in the wrong direction
you're moving x when you should be moving z, and viceversa
that'
that's what it comes off as anyways, or is atleast one problem
also your Screen pos comparisons seem wrong, for most of them
Oh my bad I misread lol
Oh yeah this would have been good to share at the start
the camera always goes down, if i aim left nothing happens, if i aim up it goes left and if i aim top right it goes up
i feel like the pokemon that hurt itself in its confusion
when i said your comparisons seem wrong, i mean you're only compariong against one corner of the screen
wait im comparing against a corner
you should be comparing with
x < 0 + ScrollMargin
x > Screen.Width - ScrollMargin
y < 0 + ScrollMargin
y > Screen.Height - ScrollMargin
Note that you're moving the camera according to world axis directions but your camera is rotated 45 degrees so that's not going to line up with the camera orientation
Hello all. The movement speed for players in my game is different on my pc from other pcs. What could be causing this? Here is my code for movement.
I'm not sure if the code is the problem because it was working not too long ago.
Don't ever use deltaTime with velocity like that
Just completely remove it, and lower speed (because you will no longer be multiplying it by a tiny fraction)
Also, it looks like your !ide is not configured? Can't tell from just that
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Well yeah, Input should not be white. Definitely not configured
It will make a HUGE difference in coding. Error underlining (for more than just basics), suggested fixes, expanded autocomplete, code highlighting for ease of reading
that sounds great
When I set the RectTransform.MinAnchor and MaxAnchor (to a rectangle and not a point or line)
my gameobject scales to that size.... is there a way to make it NOT do that?
I even changed SizeDelta after setting min and max anchor and it still stretches my game object
width/height
is that a property in RectTransform im not seeing?
I fixed it with
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length);
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, width);
but now im getting a different issue 😮
ill need to grab a gif of it
the highlight is not anchoring correctly
im anchoring it to the grid of letters, is that not the way to go?
anchor it dont put it in stretch mode
if you want the highlight, put that on stretch mode instead and put it as child of the "hightlight" rect transform
im sorry im not sure im understanding correctly 😦
which one is it suppose to be?
Hey, Can anyone please help why am I getting such a camera behaviour. it starts alright, but as soon as I press the home button and the app goes to bg, then open it again it shows this flickering behaviour. Any potential insights why this is happening to my game?
we should move this in #📲┃ui-ux
sorry!
what I would do is put the anchor first on top left corner, then achor that to the first letter in correct word
not with this video alone
this just shows us the symptom not the cause
(im no pro but) the z position of your camera might be the same as something else possibly? so it might be flickering between the black and what you want
the blind guiding the blind
the camera positioning is fine thats why the game runs fine at launch its just popping up when I reopen it after it has gone in background
can you reproduce the issue on another phone?
Or, even better, a phone emulator on your pc
yeah it was reproducing, then i turned off the auto graphics api and it went away from that phone but in the device I discovered it ealier its still happening
Ill have a go at that
I found it somewhere as well. will give it a go as well
that could be the solution, try it and report back, if it's not the solution then there might be some console errors that we can try to catch through connecting your phone and pc
yeah, I ll see what the logcat says and will come back
cheers for the help so far, really appreaciate
So im learning a bit of DOTS at the moment and came across this line of code, i dont rly understand it, so i know entitys are the things in your world and i know what TranformUsageFlags do but i dont understand the AddComponent method? he is doing something there that i dont understand
So i know a few things about the AddComponent, i know that u need to tell it what entity to add the components to and what type of component but why does he gives a prefab with the component? is it to know wether its a cube or circle etc...?
Is it not the prefab it will be spawning? Better ask in #1062393052863414313
then my brain isnt braining because how would it spawn a prefab when u are adding a component and ur telling what prefab he must use lol
i'll ask in dots ig
this doesnt make sense, anyone knows more?
he is spawning components but a prefab isnt a component right?
He's not passing the prefab to AddComponent, he's passing it to GetEntity to get the entity
if i understand correctly entitys are objects in your game right?
i dont understand what the prefab is meant to do? ye okay maybe tell the system what to spwn but what has that gotta do with AddComponent? why is that in the AddComponent?
I think you're missing a lot of the fundamental concepts you need to be diving into DOTS
Any tips on how to create such a bar such that the width remains the same but the graduations can change?
I want to create one to show my current magazine size, so it would be anywhere from 2 segments (shotgun) to 30 segments (rifle).
I am open to purchasing one too from the asset store.
with a bit of clever math you can probably just cheap it with using gridlayout component
otherwise you'd probably need a shader, or generate a mesh
I tried using horizontal layout component to see if I could just add/remove some elements. But it doesn't just work. As you can see the left and right elements don't exactly center. Definitely a lot of math involved
gridlayout match the X cell size with the amount of segments within that space
just need to do some math with that, or assign them specific sizes manually and call it done lol
horizontal layout by itself should do the trick. Make sure your layout component controls child width
you need to have the layout force expand child width, or add a layout element to the children that makes them flexible
tru i forget the option is there to control child size
Hey, has anyone tried to build webgl builds but not from player settings, but rather a custom solution. I am building some ci/di tooling and I am having issues with webgl local host.
this is the error that I get
Unable to parse Build/not-squidgame-webgl-build.framework.js.gz! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: gzip" present. Check browser Console and Devtools Network tab to debug.
This is the error that I get
from browser console
Failed to download file Build/not-squidgame-webgl-build.data.gz
what would be the fastest(optimized) way to combine 5-6 array with around 15k elements in each array....the thing is the elements in the arrays are continuously changing after some frames...i am implementing grass rendering in a huge space, here i have to gather all the instance positions from 5-6 visible zones having ~15k positions per zone and send this huge combined array to a buffer in a compute shader....any help would be great...
array.CopyTo()?
If you wanna be completely overkill you can probably turn it into a native array and then make several parallel jobs each to copy a single array to a portion in the combined native array. You need to override saftey handles and stuff for that tho
seems a heavy work...i'll try, thanks...
Sorry I take that back, you don’t need to mess with saftey stuff at all—I was thinking of a buffer
copyTo is taking a lot performance cost and collecting lot garbage...if you don't mind do you know of anything else?
i will try that job in a bit, i wanna see if there's any straightforward way to do this except job
You're probably using a graphics/compute buffer already, no? Why not just set the data into it with certain offset?
i am using dawMeshInstanceIndirect, yeah...i didn't know about that offset thing...any good article regarding that world be helpful
Make sure your buffer is dynamic too then
The documentation. Look at the overloads at the bottom:
https://docs.unity3d.com/ScriptReference/ComputeBuffer.SetData.html
That reminds me—compute buffers have a begin write method and end write. For max speed you should use those
They have less overhead
will look into it for sure...
thanks dude...gonna try this out
most of the time document page goes over my head....shall i just state what i am trying to do? so that i can get some help from you?
Didn't you say already? Copy from several arrays into a buffer to use the data in a compute shader?
As for the docs, you've gotta learn how to read them. What exactly do you not understand?
should've tried to implement it first...sorry....if i find complexities further, i will let you know, thanks
Hey guys--I'm doing some questionable things in jobs, and I found something quite annoying. To use a callback I have to compile it into a Burst function pointer. I can't use a normal function pointer because Burst needs it to be Cdecl, and defining that as a function attribute is not available.
[BurstCompile]
static unsafe void OnEntityFound(UIntPtr nEntity, BirdEntity* bird)
{
//Do something
}
context->sTree.QueryAsync(new STree.TreeNode.Bounds{
Min = bird->GCoord - new int3(settings.flight.flightDistance),
Max = bird->GCoord + new int3(settings.flight.flightDistance)
}, BurstCompiler.CompileFunctionPointer<Action<UIntPtr>>((entity) => OnEntityFound(entity, bird)));
All in all, I can do CompileFunctionPointer inside a job to create a usable callback, however inside callbacks I want to use some captured variables. As it's static I have to pass it through as an argument; the normal managed way to do this is to make a lambda which is not static and is able to capture your context variables--but I can't do that(hence why the code doesn't work) because the lambda is managed and is not BurstCompilable--is there a good way to get around this?
Because right now the best solution is to pass the callee function the context parameter just to have it call the callback with the context parameter.
For starters !code
📃 Large Code Blocks
Use 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 format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Oh so that’s how ppl do that thx
hello I saw this one video about this guy making a game that deletes itself when you die, just curious how would you do it? I would like to try / understand how he did it, because from what I know, it is not possible to delete an application that is running, but you need it to be running in order to detect deaths and activate the script that deletes the game
https://www.youtube.com/watch?v=nIdO1Z8mD7Q 9:22
Its is done! I have finished me refactor of my movement script
to get it to work w/ rotation
@rigid island @mossy snow thank you so much!! Got it to work. I was trying to tile the blue lines instead of the red bars, and your idea worked perfectly!
nicee!
ShadowCaster2DCreator.cs
https://pastebin.com/YzyXNUq0
S_PlayerTerraform.cs
https://pastebin.com/t534izqv
hi im having trouble figuring out this error that only pops up when i try to build, but not in play mode, i tried restarting unity, googling etc but theres no fix i can find, and theres no spellling mistakes either i think
ShadowCaster2DCreator only exists #if UNITY_EDITOR, but in S_PlayerTerraform you're referencing and using it regardless of whether or not you're in the editor
ohh ill try messing with that
ye i didnt even see that lol (i got the script off a youtube guide)
thanks lol
Hey, what does {get; set} and {get; private set;) mean in unity?
ty
yep works now after i wrap both scripts in if unity editor thanks
I'm not sure if that's the solution you'll actually want though - PlayerTerraform looks an awful lot like a gameplay mechanic which you'd want to include in a build. I can't speak to ShadowCasterCreator - I'm really not sure what it's doing with all of that reflection and such...
yeah i just realised after i sent that message haha
figuring out how to remove shadow caster's unity editor bracket without breaking the script rn
i've only given it a cursory glance, but isn't the only part of the ShadowCaster2DCreator file that needs to be editor only the custom editor for it? just take that bit out and put it in its own file in a folder titled Editor
ohhh ill try that haha
yeah i frankensteined the run time in it was meant to be editor only
The documentation. Look at the overloads
So is there any way I can have a rigidbody not transfer its velocity to something it collides with?
The OTHER object could be kinematic and not react to it.
Or you could disable the interaction between their layers via the layer matrix.
Other than that, not really
You could stop the rigidbody before the collision by using raycasts or something. And setting velocity to zero BEFORE it even collides
I want the layers to interact (As in I want the OnCollisionEnter function to still work). I just don't want the velocities of either object to be affected
Then no. Not really possible
Originally the plan was to simply have it be a trigger, but apparently triggers only work discretely
What do you mean discretely?
They can be triggered as granularly as normal collisions
I mean that a fast moving trigger can phase through a wall if it's moving fast enough
As can a non-trigger collider
Being a trigger won't actually affect it any differently in that regard
Yeah, but the rigidbody has options to make sure that doesn't happen and none of them seem to work with triggers
Continuous collision mode does work with triggers
I tried and I can't get it to work for the life of me
But if it is going fast enough, it will work with neither
Then spatial queries are required
I'm dumbfounded. Structs can't be null!!! But it's throwing me a null exception! WTF is going on?!
public struct PolygonStruct
{
public List<Vector3> vertices;
public List<Vector2> uv;
public List<int> triangles;
public PolygonStruct(bool needsVariable = true)
{
vertices = new();
uv = new();
triangles = new();
}
public static PolygonStruct operator +(PolygonStruct a, PolygonStruct b)
{
var v = new List<Vector3>();
var t = new List<int>();
var u = new List<Vector2>();
if(a.vertices.Count != 0)
v.AddRange(a.vertices);
if(a.triangles.Count != 0)
t.AddRange(a.triangles);
if(a.uv.Count != 0)
u.AddRange(a.uv);
if(b.vertices.Count !=0)
v.AddRange(b.vertices);
if(b.triangles.Count !=0)
{
int prevTCount = Mathf.Max(0, a.triangles.Count - 1);
foreach (int i in b.triangles)
{
t.Add(i + prevTCount);
}
}
if(b.uv.Count !=0)
u.AddRange(b.uv);
a.vertices = v;
a.triangles = t;
a.uv = u;
return a;
}
}
At a guess you are not calling the correct constructor
Share the code/line that throws the error.
PolygonStruct polies = new PolygonStruct();
if (cap)
{
PolygonStruct capPoly = MakePolygon(vert0, vert1, vert2, vert3,inv);
capPoly.uv = new()
{
new Vector2(0, 1),
new Vector2(1, 1),
new Vector2(0, 1),
new Vector2(1, 1)
};
polies+= capPoly;
}
polies+= MakePoly(vert0,vert1,inv);
polies+= MakePoly(vert1,vert2,inv);
polies+= MakePoly(vert2,vert3,inv);
polies+= MakePoly(vert3,vert1,inv);
Error's at polies+= capPoly; or the one += after that if cap is false.
there you go
PolygonStruct polies = new PolygonStruct();
your Lists are not initialized
Is that ProceduralGeneration line 188?
yes
But doesn't the constructor
public PolygonStruct(bool needsVariable = true)
{
vertices = new();
uv = new();
triangles = new();
}
initializes them?
yes, sorry, i missed the default value
I'd made constructor parameterless, but it won't let me =\
tbh I see no reason why this is a struct in the first place
Ok so if I go
PolygonStruct polies = new PolygonStruct(true);
instead of
PolygonStruct polies = new PolygonStruct();
the error is gone now... what the hell. And I still can't make parameterless constructor, so is this how I'm supposed to initialize lists?
yes, you cannot overide the default parameterless constructor for structs only for classes
why did you make it a struct when all it contains are references?
Lists are references?
of course, List is a class
They are of type Vectr3 and int, not objects or components... Aren't those variables?
irrelevant
TBH it was a simple array before, I changed them to lists in trying to figure out what causes the exception
but Array is also a class so no difference
if you are trying to get cloning on the cheap it ain't gonna work
I'm not doing cloning, I'm trying to simplyfy procedural mesh generation so I won't have to manually punch in vertexes and triangles and shit
Is there way to set Halo component's Size from code?
I tried this but it doesnt set the value (it only works for reading the current value)
halo = new SerializedObject(GetComponent("Halo"));
halo.FindProperty("m_Size").floatValue = haloSize;
I bfigured that passing the data needed to make a polygon around as a single struct variable would be simpler than every function requiring three variables
just make it a class, it will be more efficient as well
Hey guys, I have an error in my game here, whenever i press the D key it's like teleporting or glitching
here's the code
!code
📃 Large Code Blocks
Use 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 format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.

